How to extract data that is not missing value nan with pandas
I was just thinking about how to extract the list of member stores of Go To EAT in Chiba prefecture, so I summarized it with reference to the article.
import pandas as pd
import io
data = """
name,Number of times,start,End
Ponsuke,1,9:00,18:00
Ponsuke,2,18:00,
Ponsuke,3,9:00,13:00
Ponsuke,4,,
Ponsuke,5,9:00,
Ponsuke,6,18:00,
Ponsuke,7,12:00,
Ponsuke,8,12:00,
Ponsuke,9,,18:00
Ponsuke,10,,
"""
df = pd.read_csv(io.StringIO(data))
df
name | Number of times | start | End | |
---|---|---|---|---|
0 | Ponsuke | 1 | 9:00 | 18:00 |
1 | Ponsuke | 2 | 18:00 | nan |
2 | Ponsuke | 3 | 9:00 | 13:00 |
3 | Ponsuke | 4 | nan | nan |
4 | Ponsuke | 5 | 9:00 | nan |
5 | Ponsuke | 6 | 18:00 | nan |
6 | Ponsuke | 7 | 12:00 | nan |
7 | Ponsuke | 8 | 12:00 | nan |
8 | Ponsuke | 9 | nan | 18:00 |
9 | Ponsuke | 10 | nan | nan |
df[(df.loc[:, "start"].notnull() == True)]
df[(df.loc[:, ["start", "End"]].notnull() == (True, True)).all(axis=1)]
df[(df.loc[:, ["start", "End"]].notnull() == (True, True)).any(axis=1)]
df[(df.loc[:, ["start", "End"]].notnull() == (False, True)).all(axis=1)]
Recommended Posts