循环超过2个列表,从多个Excel工作表中创建单独的DFS
我在以下Excel工作簿中阅读了40张纸。以下在所有工作表中读取:
df = pd.read_excel(file_path, sheet_name = None)
所有工作表都具有相同的列,但是相关列在每个工作表中的不同行开始,因此我正在编写下面的每张表格以创建每个表:
df2 = df[Sheet_Name]
df2.columns = df2.iloc[20]
我可以使用该代码40次复制此代码,相关的行索引,但是必须有一个可以清洁代码的循环函数。
我正在考虑有2个列表,名称&行索引,该功能迭代为每个工作表创建单独的DF。
这可能吗?
感谢您的帮助
I've read in the below excel workbook which has 40 sheets. The below reads in all the worksheets:
df = pd.read_excel(file_path, sheet_name = None)
All the worksheets have identical columns, but the relevant columns start at different rows in each worksheet, so I'm writing the below to create a df from each sheet:
df2 = df[Sheet_Name]
df2.columns = df2.iloc[20]
I could replicate this code 40 times with the relevant row index, but there has to be a function with a loop that can clean the code.
I was thinking of having 2 lists, sheet name & row index, which the function iterates over to create a separate df for each worksheet.
Is this possible?
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我应该使用next()
我没有运行此代码,但是这个想法值得尝试
It should be possible using next()
I did not run this code, but the idea is worth trying