[英]Python Pandas read_csv not importing correctly
我有一個.xls
文件,看起來與此類似...
Value of Construction Put in Place...
(Millions of Dollars....)
Blank Row
Date Total_Construction Total Residential Total Nonresidential...Columns
Dec-15 1,116,570 435,454 681,217
Nov-15 1,115,966 432,295 683,671
Oct-15 1,122,749 431,164 691,585
.
.
.
我正在嘗試導入文件以獲取以下信息:
Date Total_Construction Total Residential Total Nonresidential
Dec-15 1,116,570 435,454 681,217
Nov-15 1,115,966 432,295 683,671
Oct-15 1,122,749 431,164 691,585
.
.
.
使用以下代碼:
for chunk in pandas.read_csv('/PATH/totsatime.xls',
names = ['Date', 'Total Residential', 'Total Nonresidential'],
header = 4,
chunksize = 1,
skiprows = range(1, 4),
thousands = ','):
if chunk['Date'] == 'Dec-01':
break
else:
df = pandas.DataFrame(chunk)
但是,我最終得到以下結果:
Date Total Residential Total Nonresidential
Lodging NaN NaN
Office NaN NaN
Commercial NaN NaN
Health care NaN NaN
日期最終從我不導入的列中格式化。 任何建議將不勝感激。
先感謝您。
不要使用read_csv
導入xls文件。 使用read_excel
。 參見http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.