CSV文件:(sample1.CSV)
id;name;desc;hist
1;Fulano;A;action: Test1\ndate: 04/10/2021 09:00:00\n\naction: Test2\ndate: 04/10/2021 09:00:00\n\naction: Test3\ndate: 04/10/2021 09:00:00\nauto: TESTE\n\n
2;Ciclano;B;action: Test1\ndate: 03/02/2021 14:23:24\n\naction: Test2\ndate: 03/02/2021 14:23:24\n\naction: Test3\ndate: 03/02/2021 14:23:24\nauto: TESTE\n\n
3;Beltrano;C;naction: Test3\ndate: 04/10/2021 09:00:00\nauto: TESTE\n\n
我想将CSV的“hist”列转换为以下输出
|id|name |desc|action|date |auto
|1 |Fulano |A |Test1 |04/10/2021 09:00:00 |
|1 |Fulano |A |Test1 |04/10/2021 09:00:00 |
|1 |Fulano |A |Test1 |04/10/2021 09:00:00 |TESTE
|2 |Ciclano |B |TEST3 |03/02/2021 14:23:24 |
|2 |Ciclano |B |TEST3 |03/02/2021 14:23:24 |
|2 |Ciclano |B |TEST3 |03/02/2021 14:23:24 |TESTE
|3 |Beltrano|C |TEST2 |04/02/2021 14:23:24 |TESTE
我已经将csv读入数据帧,但我不知道如何转换它?有人能帮我吗
您可以解析csv文件并提取最后三个字段:
我只使用pandas和一个helper函数就成功了。我就是这样做的:
这里真正重要的是:分解包含dict列表的列,并使用json_规范化自动解析结果
谢谢
相关问题 更多 >
编程相关推荐