首页 > 解决方案 > 熊猫:从excel中拆分合并的标题

问题描述

我有一个像这样合并标题的excel文件

我的excel表头

我想要的是使用熊猫这样的标题

我在找什么

我尝试使用此解决方案: https ://stackoverflow.com/a/27424102/12934577

但它回来了 sequence item 0: expected str instance, float found

标签: pythonexcelpandas

解决方案


您可能需要str像在那个答案中那样使用:

df.columns = df.iloc[0:2].apply(lambda x: '.'.join([str(y) for y in x if y]), axis=0)

推荐阅读