Reading csv like file to pandas

折月煮酒 提交于 2019-12-25 08:39:51

问题


I am trying to read an Excel file into pandas, but I get the message format and extension of the file don't match.

When I try to use read_excel, I get an error message, I am therefore using read_csv.

This is where the issue is; my 'Excel like' file has empty cells on some rows, and it creates a weird df, where some field are shifted:


My code is below:

2010 = pd.read_csv(r'{0}\\file.xls'.format(path_temp),sep = 
r'\t*',encoding='iso-8859-2')

In the output, column Outcome appears in 6th (date 4) column of the data frame from row 8. Would you know of a workaround? I need to load this file automatically every 15mins, meaning I d like to avoid a manual open and save as with excel


回答1:


Your separator is a regex. sep=r'\t*' matches any number of consecutive tabs, and so what should be blank cells get treated as a single delimiter. Try sep='\t' instead.



来源:https://stackoverflow.com/questions/44204770/reading-csv-like-file-to-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!