[Python] How to read excel file with pandas

[Python] How to read excel file with pandas

How to read an excel file with pandas.

Official page ・ Pandas.read_excelXrld


**table of contents**
  1. [Install Library](Install # 1 Library)
  2. [Table to read](# 2 Table to read)
  3. [Read File](# 3 Read File)
  4. Default
  5. [Read by sheet number](#Read by sheet number)
  6. [Read by sheet name](#Read by sheet name)
  7. [Option](# 4 option)

## 1. 1. Library installation Install the libraries needed to read the excel file.

Installation


pip install -U xlrd
pip install -U pandas

①xlrd └ Library to read excel file  └「.xls」「.xlsx」 ②pandas └ Library for data analysis

About pip [here](https://qiita.com/yuta-38/items/730bf91526f92fe0b41a#3-pip%E3%81%AE%E4%B8%BB%E8%A6%81%E3%82% B3% E3% 83% 9E% E3% 83% B3% E3% 83% 89% E4% B8% 80% E8% A6% A7% E6% 97% A9% E8% A6% 8B% E8% A1% A8)


## 2. Table to read ・ Table including 3 sheets -File path "~ / desktop / GA-demo.xlsx"

image.png

3. 3. Read file

① Default ② Read by sheet number ③ Read by sheet name


### ① Default The first sheet is read.

Default


import pandas as pd
df = pd.read_excel('~/desktop/GA-demo.xlsx')
df

image.png


### ② Read by sheet number Describe `sheet_name = n` as an option. └ "n": Sheet number. └ Sheet number starts from 0.

Specified by sheet number


import pandas as pd
pd.read_excel('~/desktop/GA-demo.xlsx', sheet_name=1)

image.png


### ③ Read by sheet name Describe `sheet_name ='A'` as an option. └ "A": Sheet name

Read by sheet name


import pandas as pd
pd.read_excel('~/desktop/GA-demo.xlsx', sheet_name='Data set 2')

image.png


## 4. option Options are available when loading. -Specify the row that will be the header (column name) -Specify the column that will be the index (row name) -Specify the number of lines to read -Read the specified number of lines from the bottom Etc. are possible.

Almost the same as the options when reading a csv file.

Click here for details (# https://qiita.com/yuta-38/items/e1e890a647e77c7ccaad)

Recommended Posts

[Python] How to read excel file with pandas
How to read an Excel file (.xlsx) with Pandas [Python]
How to convert JSON file to CSV file with Python Pandas
[Python] How to deal with pandas read_html read error
[Python] How to output a pandas table to an excel file
Read csv with python pandas
[Python] How to read a csv file (read_csv method of pandas module)
How to measure mp3 file playback time with python
[Python] How to use Pandas Series
Output to csv file with Python
Create an Excel file with Python3
High resolution acoustic signal processing (1) --How to read 24-bit wav file with Python
How to get started with Python
How to use FTP with Python
How to calculate date with python
Excel aggregation with Python pandas Part 1
How to switch the configuration file to be read by Python
Try to operate an Excel file using Python (Pandas / XlsxWriter) ②
[Python] How to change EXCEL file saved in xlsb to xlsx
[Python Kivy] How to create an exe file with pyinstaller
Excel with Python
[Python] How to convert db file to csv
[Python] Summary of how to use pandas
How to read pydoc on python interpreter
Read CSV file with python (Download & parse CSV file)
How to convert Python to an exe file
Quickly create an excel file with Python #python
Convert Excel data to JSON with python
How to work with BigQuery in Python
Let's read the RINEX file with Python ①
How to do portmanteau test with python
Excel aggregation with Python pandas Part 2 Variadic
How to display python Japanese with lolipop
Create Excel file with Python + similarity matrix
How to enter Japanese with Python curses
[Easy Python] Reading Excel files with pandas
[Python] How to deal with module errors
How to read CSV files in Pandas
How to read problem data with paiza
How to install python3 with docker centos
[Automation] Read mail (msg file) with Python
How to paste a CSV file into an Excel file using Pandas
How to make a command to read the configuration file with pyramid
[ROS2] How to play a bag file with python format launch
How to upload with Heroku, Flask, Python, Git (4)
How to enjoy programming with Minecraft (Ruby, Python)
[REAPER] How to play with Reascript in Python
Read and format a csv file mixed with comma tabs with Python pandas
How to do multi-core parallel processing with python
How to install Python
Convert 202003 to 2020-03 with pandas
How to read PyPI
Read Python csv data with Pandas ⇒ Graph with Matplotlib
How to create a JSON file in Python
Convert svg file to png / ico with Python
How to crop an image with Python + OpenCV
How to install python
Read table data in PDF file with Python
[Python] How to read data from CIFAR-10 and CIFAR-100
How to read JSON
Read CSV file: pandas