我有以下数据框:
raw_data = {'name': ['Willard', 'Nan', 'Omar', 'Spencer'],
'Last_Name': ['Smith', 'Nan', 'Sheng', 'Poursafar'],
'favorite_color': ['blue', 'red', 'Nan', "green"],
'Statues': ['Match', 'Mis-Match', 'Match', 'Mis_match']}
df = pd.DataFrame(raw_data, columns = ['name', 'age', 'favorite_color', 'grade'])
df
我想执行以下任务:
你们能帮我吗?
答案 0 :(得分:1)
df1 = df[df['Statues'] == 'Match']
df2 = df[df['Statues'] =='Mis-Match']
如果缺少的值不是字符串,请使用Series.isna
和
Series.notna
:
df3 = df[df['Name'].isna() & df['Last_NameName'].isna() & df['favorite_color'].notna()]
如果Nan
是字符串,则用Nan
进行比较:
df3 = df[(df['Name'] == 'Nan') &
(df['Last_NameName'] == 'Nan') &
(df['favorite_color'] != 'Nan')]