简体   繁体   English

Pandas read_csv 在第一列上失败

[英]Pandas read_csv fails on first column

I have some data from https://github.com/CSSEGISandData/COVID-19/blob/master/csse_covid_19_data/csse_covid_19_daily_reports/ which looks like:我有一些来自https://github.com/CSSEGISandData/COVID-19/blob/master/csse_covid_19_data/csse_covid_19_daily_reports/的数据,看起来像:

Singapore,2020-04-17 23:30:32,1.2833,103.8333,5050,11,708,4331,Singapore
Singapore,2020-06-12 05:09:52,1.2833,103.8333,39387,25,27286,12076,Singapore,673.2425774010173,0.06347271942519106

When I read that with pandas, sg = pd.read_csv("singapore.csv", names=["Country_Region", "Last_Update", "Lat", "Long", "Confirmed", "Deaths","Recovered","Active"]) it bizarrely looks like:当我用 pandas 阅读时, sg = pd.read_csv("singapore.csv", names=["Country_Region", "Last_Update", "Lat", "Long", "Confirmed", "Deaths","Recovered","Active"])它奇怪地看起来像:

熊猫输出

It would look like the CSV is not properly read... why?看起来 CSV 没有被正确读取……为什么?

Bonus: How do I "clean" data that has added columns to a data structure like what has happened between here and here .奖励:我如何“清理”已将列添加到数据结构的数据,例如herehere之间发生的情况。

https://github.com/kaihendry/covid19-sg/blob/master/pandas.ipynb https://github.com/kaihendry/covid19-sg/blob/master/pandas.ipynb

You need to tell pandas not to use the first column as the index by passing: index_col=False to your read_csv() call.您需要告诉 pandas不要将第一列用作索引,方法是将: index_col=False传递给您的read_csv()调用。

That will resolve the "bizarre" data.这将解决“奇怪”的数据。

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

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