Study Notes (04): Python data cleaning real - Find and modify data

Learning immediately: https://edu.csdn.net/course/play/26990/361125?utm_source=blogtoedu

1, modify

Modify the line

df1.loc [df1 [ 'gender'] == '0', 'gender'] = 'F'

Modify column

df1.rename (columns = { 'user_id': 'User ID', 'gender': 'Sex'}, inplace = True)

Modify Index

df1.rename(index = {3:334,4:3355},inplace = True)

Reset Index

df1.reset_index(drop =True,inplace = True)

2, the query

Screening travel

df[df['buy_mount']>10]

df[(df['buy_mount']>10) & (df['day'] >20140101)]

df[df['buy_mount'].between(4,10,inclusive = True)] 闭区间

df[df['cat'].isin([28,38])]

 

Released seven original articles · won praise 0 · Views 123

Guess you like

Origin blog.csdn.net/qq_42108777/article/details/104234057