notna
--Environment --macOS Catalina version 10.15.7 - Python 3.8.5 - pandas 1.1.3
import pandas
if __name__ == '__main__':
df = pandas.read_csv('CSV.csv')
print(df[df.query('name== "Ponsuke"')['start'].notna()])
Error message
pandas.core.indexing.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).
Because the index of the index of the DataFrame you are trying to extract is not in the result of notna
?
I want someone to tell me.
#The index of the DataFrame you are trying to extract is 0~There are 40 up to 39
print(df)
#Name Count Start End
#0 Ponsuke 1 9:00 18:00
# ...abridgement...
#39 Ponsuke 10 NaN NaN
#The index of the result of notna is full of missing numbers and only 10
print(df.query('name== "Ponsuke"')['start'].notna())
# 0 True
# 2 True
# 5 True
# 11 True
# 14 False
# 21 True
# 24 True
# 29 False
# 34 True
# 39 False
# Name:start, dtype: bool
If you extract from a DataFrame that matches the index of the result of notna
, it seems quite so
#DataFrame that fits the index of the result of notna
print(df.query('name== "Ponsuke"'))
#Name Count Start End
#0 Ponsuke 1 9:00 18:00
#2 Ponsuke 3 9:00 13:00
#5 Ponsuke 7 12:00 NaN
#11 Ponsuke 5 9:00 NaN
#14 Ponsuke 4 NaN NaN
#21 Ponsuke 2 18:00 NaN
#24 Ponsuke 6 18:00 NaN
#29 Ponsuke 9 NaN 18:00
#34 Ponsuke 8 12:00 NaN
#39 Ponsuke 10 NaN NaN
import pandas
if __name__ == '__main__':
df = pandas.read_csv('CSV.csv')
ponsuke = df.query('name== "Ponsuke"')
print(ponsuke[ponsuke['start'].notna()])
did it
Name Count Start End
0 Ponsuke 1 9:00 18:00
2 Ponsuke 3 9:00 13:00
5 Ponsuke 7 12:00 NaN
11 Ponsuke 5 9:00 NaN
21 Ponsuke 2 18:00 NaN
24 Ponsuke 6 18:00 NaN
34 Ponsuke 8 12:00 NaN