I really like the query
method. What is the null
query that select all the items? I have tried df.query("True")
, but it doesn't work.
The only thing I have found to work is df.query("index == 0 | index != 0")
.
Why "True" is not working, it is a predicate.
For me works:
df.query("index")
Sample:
df = pd.DataFrame({'A':[1,2,3],
'B':[4,5,6]},
index=[-1,4,5])
print (df)
A B
-1 1 4
4 2 5
5 3 6
a = df.query("index")
print (a)
A B
-1 1 4
4 2 5
5 3 6
If index values are not negative, use:
a = df.query("index > -1")
print (a)
A B
0 1 4
1 2 5
2 3 6
EDIT by comment:
I am not query
expert, but if use True
only, it search values in index:
df = pd.DataFrame({'A':[1,2,3],
'B':[4,5,6]},
index=[True,0,'d'])
print (df)
A B
True 1 4
0 2 5
d 3 6
a = df.query("True")
print (a)
A 1
B 4
Name: True, dtype: int64
b = df.query('0')
print (b)
A 2
B 5
Name: 0, dtype: int64
Another crazy index:
df = pd.DataFrame({'A':[1,2,3],
'B':[4,5,6]},
index=[True,True,True])
print (df)
A B
True 1 4
True 2 5
True 3 6
a = df.query("True")
print (a)
A B
True 1 4
True 2 5
True 3 6
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.