df1['2018']
df1['2017':'2018']
df1['2018-07']
df1['2018-05-06':'2018-05-06']
import pandas as pd
aa =r'./data/mingribooks.xls'
# 解决数据输出时列名不对齐的问题
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
df = pd.DataFrame(pd.read_excel(aa))
df1=df[['订单付款时间','买家会员名','联系手机','买家实际支付金额']]
df1 = df1.set_index('订单付款时间') # 将date设置为索引
# 获取某个区间数据
print(df1['2018-05-11':'2018-06-10'])
print(df1.truncate(after = '2018-11'))
print(df1.truncate(before='2018-01'))
dfs= [df1, df2, df3]
result = pd.concat(dfs)
result = pd.concat(dfs, keys=['1月', '2月', '3月'])
result = pd.concat([df1, df4], axis=1)
result = pd.concat([df1, df4], axis=1, join='inner')
result = pd.concat([df1, df4], axis=1, join_axes=[df4.index])
import pandas as pd
import glob
filearray=[]
filelocation=glob.glob(r'./data/XS/*.xls') # 获取程序所在data/XS文件夹下的所有.xls文件
for filename in filelocation: # 遍历文件夹
filearray.append(filename)
res=pd.read_excel(filearray[0])
for i in range(1,len(filearray)): # 读取指定路径下的Excel并进行合并
A=pd.read_excel(filearray[i])
res=pd.concat([res,A],ignore_index=True,sort=False)
print(res.index)
writer = pd.ExcelWriter('output.xls') # 合并后数据写入Excel
res.to_excel(writer,'sheet1')
writer.save()