I have a python function that get a pandas dataframe and perform on it a condiotion by the function "query" of DataFrame.
So simple conditions like =, != and all that it's ok.
But I want it to perform a conditions with "like". Is that possible?
Also, I want to check if some column is bigger than "now"...
How could I do that ?
Demo:
In [166]: now = pd.datetime.today()
In [167]: df
Out[167]:
date s
0 2017-01-18 sample string
1 2017-12-01 blah-blah
2 2017-08-17 a key
In [168]: df.query("s.str.contains('key')", engine='python')
Out[168]:
date s
2 2017-08-17 a key
In [169]: df.query("s.str.contains('key') or date > @now", engine='python')
Out[169]:
date s
1 2017-12-01 blah-blah
2 2017-08-17 a key
I think LIKE
functionality is not implemented to query
native way, need contains
, match
and similar functions.
For compare with today:
now = pd.datetime.today()
df.query("col > @now")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With