我想知道如何才能在合并/合并的Excel文件中添加额外的列(另请参见我的previous question)。在
Excel文件如下所示:
我所拥有的是:import xlwt
import os
import pandas as pd
from os.path import basename
files = os.listdir('C:\\Kids')
files_xls = []
for f in files:
if f[-3:] == 'xls':
fff = 'C:\\Kids\\' + f
files_xls.append(fff)
df = pd.DataFrame()
for f in files_xls:
data = pd.read_excel(f
team_name = basename(f)[0:basename(f).find(' ')-1]
team_code = basename(f)[basename(f).find(' ')+1 : basename(f).find('.xls')]
data.index = [team_code] * len(data) # I can have either ‘team_code’ or
# ‘team_name’ added into the 1st column,
# but I want them to be added into 2
# different columns
df = df.append(data)
df.to_excel("C:\\Kids\\combined2.xls")
因此,只有1列可以添加到我想要的内容中,但是我需要在单独的列中列出“team_name”和“team_code”。比如:
我怎么能做到呢?我试过这样的方法:
^{pr2}$
但它不起作用。在