Как преобразовать файл csv в файл json, чтобы каждый столбец csv представлял собой список в файле json? [дубликат] ⇐ Python
Как преобразовать файл csv в файл json, чтобы каждый столбец csv представлял собой список в файле json? [дубликат]
Assume we have a csv file that looks like this:
a b c 1 2 3 1 2 3 1 2 3 I would like the json file to look like this:
{ "a": [1,1,1], "b": [2,2,2], "c": [3,3,3] } I tried using pandas dataframe like this:
def func(csvFilePath, jsonFilePath): df = pd.read_csv (csvFilePath) df.to_json(jsonFilePath, indent=2) But it didnt have the expected output. Can someone point out what am I doing wrong or show another way to do it?
Источник: https://stackoverflow.com/questions/781 ... -a-list-in
Assume we have a csv file that looks like this:
a b c 1 2 3 1 2 3 1 2 3 I would like the json file to look like this:
{ "a": [1,1,1], "b": [2,2,2], "c": [3,3,3] } I tried using pandas dataframe like this:
def func(csvFilePath, jsonFilePath): df = pd.read_csv (csvFilePath) df.to_json(jsonFilePath, indent=2) But it didnt have the expected output. Can someone point out what am I doing wrong or show another way to do it?
Источник: https://stackoverflow.com/questions/781 ... -a-list-in
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение