立即学习:https://edu.csdn.net/course/play/6861/326767?utm_source=blogtoedu
数据子集的筛选:
1、列的筛选
df.column_name df['column_name']
2、行的筛选
df.loc[condition,:]
3、行列的筛选
df.loc[condition,:column_list]
import pandas as pd
data01 = pd.read_csv('E:\pylean\database\data_test01.txt',
skiprows=2,sep=',',header =None,
names=['id','age','month','day','gender','occupation','income'],
skipfooter=3,encoding='utf-8',converters={'id':str},thousands='&')
print(data01)
print(data01.gender)
print(data01['id'])
print(data01[['id','gender']])
#区别 1、点方法每次只能取一个变量,而索引法可以取多个 2、如果列名称是有两个分开的单词表示,则不能使用点方法
print(data01.loc[(data01['month']==10) & (data01['gender']=='男'),:])
print(data01.loc[data01['month']==10,['id','age','month']])
id age month day gender occupation income 0 01 1990 3 7 男 销售经理 6000 1 02 1989 8 10 女 化妆师 8500 2 03 1991 10 10 男 后端开发 13500 3 04 1992 10 7 女 前端设计 6500 4 05 1985 6 15 男 数据分析师 18000 0 男 1 女 2 男 3 女 4 男 Name: gender, dtype: object 0 01 1 02 2 03 3 04 4 05 Name: id, dtype: object id gender 0 01 男 1 02 女 2 03 男 3 04 女 4 05 男 id age month day gender occupation income 2 03 1991 10 10 男 后端开发 13500 id age month 2 03 1991 10 3 04 1992 10