简体   繁体   English

Pandas read_csv大文件将每列放入一个

[英]Pandas read_csv big file puts every column into one

I have a csv file and I'm trying to read it via pandas command read_csv. 我有一个csv文件 ,我试图通过pandas命令read_csv读取它。 However instead of reading 5 rows and 21 columns I get the following output: 但是,不是读取5行和21列,而是获得以下输出: 在此输入图像描述

There is a possible solution of manually changing the bad formatting of the file however, the real size is quite big(around 1GB) and it isnt possible to change it manually. 有一种可能的解决方案,手动更改文件的错误格式,但实际大小相当大(约1GB),并且不可能手动更改它。

Consider below solution: 考虑以下解决方案

df = pd.read_csv("test.csv", sep="\"\,\"")
data = pd.concat([df.iloc[:,0].str.split(',', expand=True).rename(columns=dict(zip([0,1], df.columns[0].split(',')))), df.iloc[:,1:]], axis=1)

Would return a (5,21) shape of data . 将返回(5,21)形状的data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM