How to read Excel data in Python? You can easily read Excel data by using the read_excel() function in the Pandas library: Import Pandas library: import pandas as pd Use the read_excel() function to read Excel files: data = pd.read_excel('path/to/file .xlsx') to read a specific worksheet: data = pd.read_excel('path/to/file.xlsx', sheet_name='Sheet1') to read a specific
How to read Excel data in Python
How to read Excel data?
To read Excel data, you can use theread_excel()
function in the Pandas library.
Detailed steps:
import pandas as pd
read_excel()
function to read an Excel file:This function needs to provide the path or file object of the Excel file, and can specify other parameters (such as where to read worksheet or column):
data = pd.read_excel('path/to/file.xlsx')
To read a specific worksheet, please enter insheet_name
Specify the worksheet name or index in the parameter:
data = pd.read_excel('path/to/file.xlsx', sheet_name='Sheet1')
To read specific columns, Please specify the name or index of the column in theusecols
parameter:
data = pd.read_excel('path/to/file.xlsx', usecols=['A', 'C'])
Read data will be stored in apandas.DataFrame
object, which can be stored in a variable:
df = pd.read_excel('path/to/file.xlsx')
Example:
Read named "example .xlsx" Excel file and store it in thedf
variable:
import pandas as pd df = pd.read_excel('example.xlsx', sheet_name='Sheet1')
The above is the detailed content of How to read excel data in python. For more information, please follow other related articles on the PHP Chinese website!