【问题标题】:append multiple excels into a single excel placed inside a folder using python使用python将多个excel附加到放置在文件夹中的单个excel中
【发布时间】:2019-09-19 08:01:45
【问题描述】:

我有多个列名相同的 Excel。我想将所有 excel 附加到一个 excel 文件中。我在下面的代码中获取输出。唯一的问题是我没有得到它的标题/标题/第一行(这是所有 excel 文件中的相同列名)。我的代码如下:

import glob
import os
import pandas as pd

output = pd.DataFrame()
for file in glob.glob(os.getcwd()+"\\*.xlsx"):
    cn = pd.read_excel(file)
    output = output.append(cn)
output.to_excel(os.getcwd()+"\\outPut.xlsx", index = False, na_rep = "NA", header=None)
print("Completed +::" )```


【问题讨论】:

  • header=None 参数表示您不想要该标头。放下它

标签: python excel python-3.x pandas


【解决方案1】:

只需更改header=True

import glob
import os
import pandas as pd

output = pd.DataFrame()
for file in glob.glob(os.getcwd()+"\\*.xlsx"):
    cn = pd.read_excel(file)
    output = output.append(cn)
output.to_excel(os.getcwd()+"\\outPut.xlsx", index = False, na_rep = "NA", header=True)
print("Completed +::" )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 2018-04-06
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多