Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created March 10, 2020 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalgjose/21db4a31a5ccee94e7bdc92204d2c0cb to your computer and use it in GitHub Desktop.
Save amalgjose/21db4a31a5ccee94e7bdc92204d2c0cb to your computer and use it in GitHub Desktop.
Python program to convert csv file to json
import pandas as pd
# Since the headers are missing in the csv file, explicitly passing the field names in the program
csv_file = pd.DataFrame(pd.read_csv("data.csv", sep = ",", names = ["EmpID", "FirstName","LastName","Salary"], index_col = False))
csv_file.to_json("data.json", orient = "records", date_format = "epoch", double_precision = 10, force_ascii = True, date_unit = "ms", default_handler = None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment