简体   繁体   English

将Excel文件导入Python

[英]Importing excel files into Python

I am a super new user of Python and have been having trouble loading an Excel file to play around with in Python. 我是Python的超级新用户,在加载Excel文件以在Python中玩耍时遇到了麻烦。

I am using Python 3.7 on Windows 10 and have tried things like using the import statement or using pip and pip3 and then install statements. 我在Windows 10上使用Python 3.7,并尝试了诸如使用import语句或使用pip和pip3的操作,然后尝试安装语句。 I am so confused on how to do this and no links I've read online are helping. 我对如何执行此操作感到很困惑,而且我在网上阅读的任何链接都无济于事。

pip install pandas
pip3 install pandas
import pandas

I just want to upload an Excel file into Python. 我只想将Excel文件上传到Python。 I'm embarrassed that it's causing me this much stress. 我很尴尬,这给我造成了很大的压力。

first of all you have to import pandas (assuming that is installed, in anaconda usually is already installed as far as i know) 首先,您必须导入熊猫(假设已安装,据我所知,anaconda中通常已安装)

import pandas as pd

to read more sheets in different dataframes (tables) 在不同的数据框(表)中读取更多工作表

xls = pd.ExcelFile(path of your file)
df_schema = pd.read_excel(xls, sheet_name=xls.sheet_names) 

df_schema is a dictionary of df in which the key is the name of the sheet and the value is the dataframe. df_schema是df的字典,其中的键是工作表的名称,值是数据框。

to read a single sheet the following should work: 要阅读一张纸,以下方法应该起作用:

xls = pd.ExcelFile(path of your file)
df = pd.read_excel(xls) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM