user2813606
user2813606

Reputation: 911

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.

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. 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. I'm embarrassed that it's causing me this much stress.

Upvotes: 0

Views: 583

Answers (1)

giulio
giulio

Reputation: 157

first of all you have to import pandas (assuming that is installed, in anaconda usually is already installed as far as i know)

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.

to read a single sheet the following should work:

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

Upvotes: 1

Related Questions