Python DataFrameを作成するその⑤
おはようございます。ちゃあ少佐です。
Python 学習21日目
今日もDataframe。。。ちょっと飽きてきた。
まぁ今日の一発目はDataframeのフィルタリング。
Name | Height | Weight | |
---|---|---|---|
0 | 佐藤 | 172 | 53 |
1 | 田中 | 160 | 50 |
2 | 鈴木 | 165 | 58 |
3 | 長谷川 | 160 | 65 |
df_165 = df[df['Height'] >= 165]
print(df_165)
結果
Name | Height | Weight | |
---|---|---|---|
0 | 佐藤 | 172 | 53 |
2 | 鈴木 | 165 | 58 |
df_ans = df[(df['Height'] >= 165) & (df['Weight'] >= 55)]
print(df_ans)
or
df_ans = df.query('Height >= 165 & Weight >= 55')
print(df_ans)
結果
Name | Height | Weight | |
---|---|---|---|
2 | 鈴木 | 165 | 58 |
df.query('Height >= 165 & Name == "佐藤"')
結果
Name | Height | Weight | |
---|---|---|---|
0 | 佐藤 | 172 | 53 |
以上、ちゃあ少佐でした。