如何在Google Colab中从Excel中读取特定的工作表

7 浏览
0 Comments

如何在Google Colab中从Excel中读取特定的工作表

现在我正在使用Google colab以这种方式读取许多文件。

linedata=files.upload()
kgdata=files.upload()
voldata=files.upload()
Masterdata=files.upload()
areadata=files.upload()
Format_out_data=files.upload()
pallet_num_data=files.upload()
line=pd.read_excel(io.BytesIO(linedata["line fixing.xls"]))
kg=pd.read_excel(io.BytesIO(kgdata["kg fixing.xls"]))
vol=pd.read_excel(io.BytesIO(voldata["vol  fixing.xls"]))
Master=pd.read_excel(io.BytesIO(Masterdata["Volume_Pallet.xls"]))
area=pd.read_excel(io.BytesIO(areadata["area fixing.xls"]))
Format_out=pd.read_excel(io.BytesIO(Format_out_data["Formate_output.xls"]))
pallet_num=pd.read_excel(io.BytesIO(pallet_num_data["Pallet_number.xls"]))

而我希望导入一个包含所有文件的单个文件,每个文件作为一个sheet。在普通的pandas中,我会使用以下代码。

df= (pd.read_excel(io=file_name,sheet_name='Sheet1'))

有人能告诉我如何在Google colab中实现相同的效果吗?

0
0 Comments

问题:如何在Google Colab中读取特定的Excel表格?

原因:用户在Google Colab中想要读取特定的Excel表格,但没有找到确切的解决方案。他发现了一种类似的方法,即每次手动导入单个文件,而是选择一次性上传所有文件。然后,通过文件名逐个进行读取。

解决方法:

1. 首先,使用以下代码将文件上传到Google Colab中:

data=files.upload()

2. 然后,使用以下代码分别读取每个特定的Excel表格:

line=pd.read_excel(io.BytesIO(data["line fixing.xls"]))
kg=pd.read_excel(io.BytesIO(data["kg fixing.xls"]))
vol=pd.read_excel(io.BytesIO(data["vol  fixing.xls"]))
Master=pd.read_excel(io.BytesIO(data["Volume_Pallet.xls"]))
area=pd.read_excel(io.BytesIO(data["area fixing.xls"]))
Format_out=pd.read_excel(io.BytesIO(data["Formate_output.xls"]))
pallet_num=pd.read_excel(io.BytesIO(data["Pallet_number.xls"]))

通过上述步骤,用户可以在Google Colab中读取特定的Excel表格。

0