我需要阅读一个excel文件,并在每张表上进行一些计算。基本上,如果列date不是“today”,它需要删除行。你知道吗
到目前为止我得到了这个代码:
你知道吗 导入日期时间 作为pd导入
'''
Parsing main excel sheet to save transactions != today's date
'''
mainSource = pd.ExcelFile('path/to/file.xlsx')
dfs = {sheet_name: mainSource.parse(sheet_name)
for sheet_name in mainSource.sheet_names }
for i in dfs:
now = datetime.date.today();
dfs = dfs.drop(dfs.columns[6].dt.year != now, axis = 1); # It is the 6th column
if datetime.time()<datetime.time(11,0,0,0):
dfs.to_excel(r'path\to\outpt\test\'+str(i)+now+'H12.xlsx', index=False); #Save as sheetname+timestamp+textstring
else:
dfs.to_excel(r'path\to\output\'+str(i)+now+'H16.xlsx', index=False)
运行脚本时,出现以下错误:
dfs = dfs.drop(...):
AttributeError: 'dict' object has no attribute 'drop'
有什么建议吗?你知道吗
谢谢!你知道吗
我认为您需要将
i
替换为dfs[i]
,因为dfs
是DataFrames
的dict:按^{} 删除所有行:
相关问题 更多 >
编程相关推荐