-
Notifications
You must be signed in to change notification settings - Fork 1
/
csv_to_json.py
19 lines (15 loc) · 1000 Bytes
/
csv_to_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Datasets used -
# top 50 spotify songs by country -https://www.kaggle.com/leonardopena/top-50-spotify-songs-by-each-country
# top 50 spotify songs in 2019 - https://www.kaggle.com/leonardopena/top50spotify2019
# top spotify songs in 2010-2019 - https://www.kaggle.com/leonardopena/top-spotify-songs-from-20102019-by-year
import pandas as pd
from pprint import pprint
# add CSV file location
csvfile = '/Users/shubhamgaikwad/Desktop/SQL-NOSQL/Spotify-project/top50.csv'
# add JSON file destination
jsonfile = '/Users/shubhamgaikwad/Desktop/SQL-NOSQL/Spotify-project/top50_2019.json'
df = pd.read_csv(csvfile, engine='python')
print("converting csv to json")
df.to_json(jsonfile, orient='records', indent=2)
# to import the json file to mongodb cluster-
#mongoimport --uri mongodb+srv://main_user:$hubham123@music-cluster.t9tjf.mongodb.net/music-data --collection music-collection --type json --file /Users/shubhamgaikwad/Desktop/SQL-NOSQL/Spotify-project/top_songs_last10_years_.json --jsonArray