Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Basic-Scripts/Dat_to_CSV/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Dat to CSV

This simple script can be used to convert files in ".dat" format to ".csv" format.


## How to use this script?

1.Install the required libraries by:

pip install -r requirements.txt

2. Open your command prompt in the directory of the script and type the following:

python dat_to_csv.py -l <your_data-file>

Example:

python dat_to_csv.py -l awesome.dat




31 changes: 31 additions & 0 deletions Basic-Scripts/Dat_to_CSV/dat_to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pandas as pd
import argparse

# Code to add the command line interface
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--datafile", required=True, help="data file ")
args = vars(parser.parse_args())

#Catching the user defined data file
data_file = args['datafile']

#Logic to make sure it is a data file.A data file ends with .dat extension

if data_file.endswith(".dat"):

#Storing the name of the file
file_name = data_file.split(".")[0]

#Collecting data of the file in a pandas object
data_of_the_file = pd.read_csv(data_file, sep="\s+")

#Converting the pandas object into a csv
data_of_the_file.to_csv(file_name+".csv", index=False)
print("Your csv file has been created successfully!!!")
else:
print("Invalid data file")

#Sample Input-Output:

#Input(At the command line): python dat_to_csv -l awesome.dat
#Output: awesome.csv
5 changes: 5 additions & 0 deletions Basic-Scripts/Dat_to_CSV/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
numpy==1.19.1
pandas==1.1.1
python-dateutil==2.8.1
pytz==2020.1
six==1.15.0