mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-27 22:11:10 +00:00
add csv to json script
This commit is contained in:
parent
6c6a236407
commit
d8f56d0d1c
|
@ -1,9 +1,8 @@
|
||||||
# CSV to EXCEL
|
# CSV to EXCEL
|
||||||
This is a simple script that lets you convert CSV files to Excel.
|
This simple script will convert CSV file to Json.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
* 2 packages required pandas and openpyxl
|
* required pandas package
|
||||||
* Use `pip install pandas` and `pip install openpyxl`
|
* Use `pip install pandas`
|
||||||
* Add path to your csv file and output excel file WITH EXTENSTION `.csv` and `.xlsx`
|
|
||||||
* Run `python script.py`
|
* Run `python script.py`
|
||||||
|
|
9
scripts/csv_to_json/README.md
Normal file
9
scripts/csv_to_json/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# CSV to EXCEL
|
||||||
|
This is a simple script that lets you convert CSV files to Excel.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
* 2 packages required pandas and openpyxl
|
||||||
|
* Use `pip install pandas` and `pip install openpyxl`
|
||||||
|
* Add path to your csv file and output excel file WITH EXTENSTION `.csv` and `.xlsx`
|
||||||
|
* Run `python script.py`
|
16
scripts/csv_to_json/script.py
Normal file
16
scripts/csv_to_json/script.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import pandas as pd
|
||||||
|
import os,json
|
||||||
|
|
||||||
|
def csv_to_json():
|
||||||
|
file = input("Enter csv path: ")
|
||||||
|
df = pd.read_csv(file)
|
||||||
|
name = os.path.basename(file).replace("csv", "json")
|
||||||
|
data = df.to_dict("r")
|
||||||
|
with open(name, "w") as file:
|
||||||
|
json.dump(data,file)
|
||||||
|
|
||||||
|
print(f"file saved at {name}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
csv_to_json()
|
Loading…
Reference in New Issue
Block a user