我有很多文件夹,每个文件夹包含一个excel文件,比如1Aug 2022,2Aug 2022.
我希望python通过所有文件夹读取,并且只打开像19AUG 2022这样的excel文件名,excel文件中有许多页,比如IP-1*,IP-2*,IP-3*。然后转到带有(IP-2*)的工作表中提取2列数据。
我怎么才能在蟒蛇身上做到呢?
发布于 2022-09-13 09:56:34
您可以使用熊猫包:https://pandas.pydata.org/
一个例子是
import pandas as pd
your_excel_path = "your/path/to/the/excel/file"
data = pd.read_excel(your_excel_path, sheet_name = "19AUG2022") # If you want to read specific sheet's data
data = pd.read_excel(your_excel_path, sheet_name = None) # If you want to read all sheets' data, it will return a list of dataframes发布于 2022-09-13 09:59:13
就像费格斯说的那样,用熊猫。
搜索所有局长的代码可能如下所示:
import os
import pandas as pd
directory_to_search = "./"
sheet_name = "IP-2*****"
for root, dirs, files in os.walk(directory_to_search):
for file in files:
if file == "19AUG2022":
df = pd.read_excel(io=os.path.join(root, file), sheet_name=sheet_name)https://stackoverflow.com/questions/73700802
复制相似问题