我试图将CSV保存到Firebase上的数据库,但问题是我有成千上万的这个:
Nro;Apellido;Nombre;Celular
1;Manchini;Mariela Gladis;+54 349 652 520 2
2;Salinas ;Eliana ;+54 113 235 878 1
,我需要这样写:
"1": {
"Apellido": "Manchini",
"Celular": "+54 349 652 520 2",
"Nombre": "Elianas"
},
"2": {
"Apellido": "Salinas ",
"Celular": "+54 113 235 878 1 ",
"Nombre": Eliana "
}
}
我试过了,但结果不是我想要的,请帮助我,我是新手:
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 "}]"
我尝试了很多不同的代码,甚至试图创建一些东西,但我没有很好的结果。
如何:
my_df = pd.read_csv('NewYork-03-19-0.csv', sep=";")