[Easy Python] Reading Excel files with pandas

What is pandas

pandas is a Python library. Pandas are mainly used when manipulating data. Pandas are essential for AI and machine learning. However, it also has a function to operate Excel files. This time, I will explain how to read an Excel file using pandas.

Excel file reading

Load only the first sheet

The contents of sample.xlsx bandicam 2020-01-20 16-36-57-804.jpg If

main.py


import pandas as pd
df = pd.read_excel('sample.xlsx')
print(df)

When you run the above main.py bandicam 2020-01-20 16-44-46-679.jpg And succeeded in reading the Excel file safely.

Read from all sheets

By the way, the second line of main.py

df = pd.read_excel('sample.xlsx', sheet_name =None)

Then you can get the data from all the sheets in sample.xlsx.

Read specified sheet

Specify by number

When sheet_name is set to None, all sheets are read. By specifying a number starting from 0 for sheet_name, the [specified number + 1] th sheet can be read.

df = pd.read_excel('sample.xlsx', sheet_name =0) #Read the first sheet
df = pd.read_excel('sample.xlsx', sheet_name =2) #Read the third sheet

Specified by name

By specifying a character string in sheet_name, you can read a sheet that has that character string in the sheet name.

df = pd.read_excel('sample.xlsx', sheet_name ='sheet1') #name is'sheet1'Sheet reading

Summary

I introduced how to read an Excel file using pandas. This feature is just the tip of the full iceberg of pandas.

It is a library that is used in a wide variety of situations, so if you are interested, please check out the detailed site.

Recommended Posts

[Easy Python] Reading Excel files with pandas
[Easy Python] Reading Excel files with openpyxl
Reading .txt files with Python
Handle Excel CSV files with Python
Excel aggregation with Python pandas Part 1
Excel with Python
[Python] Easy reading of serial number image files with OpenCV
Excel aggregation with Python pandas Part 2 Variadic
Reading and writing JSON files with Python
Handle Excel with python
[Python] Reading CSV files
Operate Excel with Python (1)
Operate Excel with Python (2)
[Python] How to read excel file with pandas
Reading and writing fits files with Python (memo)
Operate Excel with Python openpyxl
Read csv with python pandas
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Let's run Excel with Python
Manipulate excel files from python with xlrd (personal notes)
Easy folder synchronization with Python
Sorting image files with Python (2)
Sort huge files with python
[Python] Change dtype with pandas
Sorting image files with Python
Integrate PDF files with Python
Easy Python compilation with NUITKA-Utilities
Easy HTTP server with Python
Type after reading an excel file with pandas read_excel
Improve your productivity by processing huge Excel files with Python
How to read an Excel file (.xlsx) with Pandas [Python]
[Python] Loading csv files using pandas
solver> Link> Solve Excel Solver with python
[Python] Easy parallel processing with Joblib
Recursively unzip zip files with python
Manipulating EAGLE .brd files with Python
Create an Excel file with Python3
Decrypt files encrypted with OpenSSL with Python 3
Let's play with Excel with Python [Beginner]
[Python] Join two tables with pandas
Easy Python + OpenCV programming with Canopy
Easy email sending with haste python3
Reading and writing NetCDF with Python
Bayesian optimization very easy with Python
Multi-line size specification reading with python
1. Statistics learned with Python 1-1. Basic statistics (Pandas)
Read files in parallel with Python
Easy data visualization with Python seaborn.
Reading and writing CSV with Python
Easy parallel execution with python subprocess
Easy modeling with Blender and Python
[Python] Format when to_csv with pandas
[AWS] Using ini files with Lambda [Python]
[Python] Super easy test with assert statement
[Python] Easy argument type check with dataclass
Play audio files from Python with interrupts
"System trade starting with Python3" reading memo
Draw Nozomi Sasaki in Excel with python
Convert Excel data to JSON with python
Decrypt files encrypted with openssl from python with openssl
Easy web app with Python + Flask + Heroku