【问题标题】:How to read particular sheet from excel in Google Colab如何在 Google Colab 中从 excel 中读取特定工作表
【发布时间】:2020-12-26 15:32:28
【问题描述】:

现在我在 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"]))

相反,我想导入一个包含所有文件的单个文件作为工作表。在普通熊猫中,我将使用以下代码。

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

有人可以告诉如何在 google colab 中进行相同的操作吗?

【问题讨论】:

标签: excel pandas csv google-colaboratory import-from-excel


【解决方案1】:

我没有找到确切的解决方案,而是以类似的方式,而不是每次手动导入单个文件,一次选择所有文件并上传。读取将在文件名上单独发生,如下所示。

data=files.upload()

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"]))

【讨论】:

    猜你喜欢
    • 2022-12-04
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多