1. Download and import the relevant extension libraries
1Download the extension library
2pip install xlrd
3pip install pandas
4# -*- coding: UTF-8 -*-
5
6# import the pandas library
7import pandas as pd
Copy the code
2. Prepare data files

3. Read the file worksheet
 1Read excel file to specify worksheet data
 2
 3print("Worksheet: DatA1 Data contents")
 4data_fram_data1 = pd.read_excel('C:/python concentration /pandas, sheet_name='data1'5)print(data_fram_data1)
 6
 7print("Worksheet: DatA2 Data contents")
 8data_fram_data2 = pd.read_excel('C:/python concentration /pandas, sheet_name='data2'9)print(data_fram_data2)
10
11print("Worksheet: DatA3 Data content")
12data_fram_data3 = pd.read_excel('C:/python concentration /pandas, sheet_name='data3'13)print(data_fram_data3)
Copy the code
4. Basic Excel operations
 1View all column names
 2print(data_fram_data3.columns)
 3Check the data type
 4print(data_fram_data3.dtypes)
 5
 6View the first 10 rows of data
 7print(data_fram_data3.head(10))
 8# view all columns from name to age
 9print(data_fram_data3.loc[:,'name':'age'])
10# view all columns from first to third, name to age
11print(data_fram_data3.loc[1:3.'name':'age'])
12
13Drop the name column
14data_fram_data3 = data_fram_data3.drop(['name'],axis=115)print(data_fram_data3)
16# delete rows where age ==6
17data_fram_data3 = data_fram_data3.loc[-(data_fram_data3['age'] = =618)]print(data_fram_data3)
19
20# Remove duplicate age data
21data_fram_data3 = data_fram_data3.drop_duplicates(['age'22])print(data_fram_data3)
Copy the code

More exciting things to come to wechat public account “Python Concentration Camp”, focusing on Python technology stack, information acquisition, communication community, dry goods sharing, looking forward to your joining ~