[英]Read .csv file with arbitrary spaces between entries
I have a .csv
file for to read with pd.read_csv()
.我有一个.csv
文件用于读取pd.read_csv()
。 Unfortunately, each line is entered in a single cell instead of multiple cells for each column as shown below:不幸的是,每一行都在一个单元格中输入,而不是每列的多个单元格,如下所示:
I am trying something like this to read that file :我正在尝试这样的事情来读取该文件:
sheffield = pd.read_csv('data/sheffield_weather_station.csv', skiprows=8, delimiter='|', engine='python')
It gives me this output without separating each value/data.它给了我这个输出而不分离每个值/数据。 I checked the spaces between columns in the Microsoft Excel, they are arbitrary.我检查了 Microsoft Excel 中列之间的空格,它们是任意的。 Is there a specific option of pd.read_csv()
to solve this problem?是否有特定的pd.read_csv()
选项来解决这个问题?
You may try你可以试试
sheffield = pd.read_csv('data/sheffield_weather_station.csv', skiprows=8, sep='\s+', engine='python')
It is essentially the same as delim_whitespace=True
as it is an alias for the sep
parameter, see the pandas documentation on the matter.它本质上与delim_whitespace=True
相同,因为它是sep
参数的别名,请参阅有关此事的pandas 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.