I am trying to save a CSV to the database on Firebase, but the problem is that I have thousands of this:
Nro;Apellido;Nombre;Celular
1;Manchini;Mariela Gladis; 54 349 652 520 2
2;Salinas ;Eliana ; 54 113 235 878 1
and I need something like this:
"1": {
"Apellido": "Manchini",
"Celular": " 54 349 652 520 2",
"Nombre": "Elianas"
},
"2": {
"Apellido": "Salinas ",
"Celular": " 54 113 235 878 1 ",
"Nombre": Eliana "
}
}
I tried but the result is not the one that I want, Please help I am new to this:
my_df = pd.read_csv('NewYork-03-19-0.csv')
my_json = dict(my_df.set_index('Nro').groupby(level=0).apply(lambda x:
x.to_json(orient='records')))
with open('my_json.json', 'w') as outfile:
json.dump(my_json, outfile)
{"1": "[{\"Apellido\":\"Torres\",\"Nombre\":\"Loredana \",\"Celular\":\" 91 451 039 07 \"}]",
"2": "[{\"Apellido\":\"Nu\\u00f1ez\",\"Nombre\":\"Patricia\",\"Celular\":\"134 766 662 48 \"}]"
I tried many pieces of different codes and even tried to create something but I didn't have good results.
CodePudding user response:
How about :
my_df = pd.read_csv('NewYork-03-19-0.csv', sep=";")