I am fairly new to Python and this community so please forgive my amateurish attempts to explain my profound confusion on something that is most likely very obvious. Anyway..
I have a dataframe called "data". It is multiIndexed with 2 levels consisting of: "date" and "farts".
There is a single column called: "integrated_daily_difference".
You can assume "farts" is of type: 'pandas.core.index.Index' and was created via:
farts = data.index.levels[1]
Now lets imagine I would like take a slice view of my dataframe at an arbitrary index value in farts: i.e. farts[1]
Me:
data.xs(farts[1], level = 1)
Computer:
integrated_daily_difference
date
2015-05-21 00:00:00+00:00 0.000000
2015-05-22 00:00:00+00:00 0.000000
2015-05-26 00:00:00+00:00 -0.024497
2015-05-27 00:00:00+00:00 -0.051144
2015-05-28 00:00:00+00:00 -0.079841
2015-05-29 00:00:00+00:00 -0.106666
2015-06-01 00:00:00+00:00 -0.131245
2015-06-02 00:00:00+00:00 -0.157428
2015-06-03 00:00:00+00:00 -0.184057
2015-06-04 00:00:00+00:00 -0.209755
2015-06-05 00:00:00+00:00 -0.234588
2015-06-08 00:00:00+00:00 -0.262365
2015-06-09 00:00:00+00:00 -0.291890
2015-06-10 00:00:00+00:00 -0.320943
2015-06-11 00:00:00+00:00 -0.352627
2015-06-12 00:00:00+00:00 -0.381425
2015-06-15 00:00:00+00:00 -0.404055
Me:
data.xs(farts[1], level = 1) < 0
Computer:
integrated_daily_difference
date
2015-05-21 00:00:00+00:00 False
2015-05-22 00:00:00+00:00 False
2015-05-26 00:00:00+00:00 True
2015-05-27 00:00:00+00:00 True
2015-05-28 00:00:00+00:00 True
2015-05-29 00:00:00+00:00 True
2015-06-01 00:00:00+00:00 True
2015-06-02 00:00:00+00:00 True
2015-06-03 00:00:00+00:00 True
2015-06-04 00:00:00+00:00 True
2015-06-05 00:00:00+00:00 True
2015-06-08 00:00:00+00:00 True
2015-06-09 00:00:00+00:00 True
2015-06-10 00:00:00+00:00 True
2015-06-11 00:00:00+00:00 True
2015-06-12 00:00:00+00:00 True
2015-06-15 00:00:00+00:00 True
I assume this returns whether or not a value exists for any location within my sliced dataframe so the result is True?
Me:
data.xs(farts[1], level = 1).any()
Computer:
integrated_daily_difference True
dtype: bool
OK, this all kind of makes sense. Now for the weird stuff..
Me:
data.xs(farts[1], level = 1).any() < 0
Computer:
integrated_daily_difference False
dtype: bool
Huh....?
Me:
data.xs(farts[1], level = 1).any(axis = 0) < 0
Computer:
integrated_daily_difference False
dtype: bool
Me:
data.xs(farts[1], level = 1).any(axis = 1) < 0
Computer:
date
2015-05-21 00:00:00+00:00 False
2015-05-22 00:00:00+00:00 False
2015-05-26 00:00:00+00:00 False
2015-05-27 00:00:00+00:00 False
2015-05-28 00:00:00+00:00 False
2015-05-29 00:00:00+00:00 False
2015-06-01 00:00:00+00:00 False
2015-06-02 00:00:00+00:00 False
2015-06-03 00:00:00+00:00 False
2015-06-04 00:00:00+00:00 False
2015-06-05 00:00:00+00:00 False
2015-06-08 00:00:00+00:00 False
2015-06-09 00:00:00+00:00 False
2015-06-10 00:00:00+00:00 False
2015-06-11 00:00:00+00:00 False
2015-06-12 00:00:00+00:00 False
2015-06-15 00:00:00+00:00 False
Me:
data.xs(farts[1], level = 1).any(axis = 1) <= 0
Computer:
date
2015-05-21 00:00:00+00:00 True
2015-05-22 00:00:00+00:00 True
2015-05-26 00:00:00+00:00 False
2015-05-27 00:00:00+00:00 False
2015-05-28 00:00:00+00:00 False
2015-05-29 00:00:00+00:00 False
2015-06-01 00:00:00+00:00 False
2015-06-02 00:00:00+00:00 False
2015-06-03 00:00:00+00:00 False
2015-06-04 00:00:00+00:00 False
2015-06-05 00:00:00+00:00 False
2015-06-08 00:00:00+00:00 False
2015-06-09 00:00:00+00:00 False
2015-06-10 00:00:00+00:00 False
2015-06-11 00:00:00+00:00 False
2015-06-12 00:00:00+00:00 False
2015-06-15 00:00:00+00:00 False
Me:
data.xs(farts[1], level = 1).any(axis = 0) <= 0
Computer:
integrated_daily_difference False
dtype: bool
Then my computer started laughing maniacally at me and my head exploded...
But more seriously, what is going on here? My goal was to going to just try to check if all or any values in my single column dataframe meet a condition and return a boolean True or False. I don't seem to be using any() correctly, so I'm seeking help.
Any input is appreciated. Thank you in advance!