简体   繁体   English

pandas read_excel with multiindex 和 parse_date; 如何?

[英]pandas read_excel with multiindex and parse_date; how?

I am trying to use pandas read_excel to read an excel file with two header rows, and a column which contains dates.我正在尝试使用 pandas read_excel 来读取具有两个 header 行和包含日期的列的 excel 文件。 I'm trying to use the parse_dates feature to specify the date column to parse, but I'm running into some trouble, code is basically;我正在尝试使用 parse_dates 功能来指定要解析的日期列,但是我遇到了一些麻烦,代码基本上是;

dateColNms= [('start_date', '(*)Start')]
df = pd.read_excel(fileName,  sheet_name = sheetNm, skiprows=0, header= [0,1], parse_dates = dateColNms)

The code throws an error;代码抛出错误;

KeyError: '(*)Start'

I've tried variants of specifying the date column names, but none seem to work.我尝试了指定日期列名称的变体,但似乎没有一个工作。 Anyone have any pointers?有人有任何指示吗? Thanks, Weh.谢谢,韦。

It appears that you do not have a column with this name '(*)Start'.您似乎没有名为“(*)Start”的列。 Try reading excel file with parse_date='start_date' to confirm.尝试使用 parse_date='start_date' 读取 excel 文件以确认。

Thank you for your reply.感谢你的回复。 I did try using that before posting my question and it works as expected.在发布我的问题之前,我确实尝试过使用它,它按预期工作。 Below is a snapshot of the specific header column.下面是特定 header 列的快照。 Regards, Weh问候,韦

header snapshot header 快照

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

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