mask and proper index
__peter__ at web.de
Sun Feb 3 13:18:53 EST 2019
diego.avesani at gmail.com wrote:
> Dear all,
> I am trying to apply a mask to my dataframe:
> mask = (df['datatime'] > start_date) & (df['datatime'] <= end_date)
> df = df.loc[mask]
> It seems to work pretty well.
> After that I crate the cumulative of its element as:
> PP_cumPP = np.cumsum(df[PP_station])
> However, I am not able to compute PP_cumPP last element. Indeed, when I do
> I get
> and when I try to do:
> I get an error.
The ultimate problem description ;) You can certainly do better than that.
Please do always try to make your example self-contained so that a reader
can run it and see the same error as you do.
At the very least cut and paste the traceback and the error message you are
> What I am doing wrong?
My steps to reproduce what is probably your problem:
>>> df = pd.DataFrame([,,], columns=["foo"])
>>> odd = df.loc[df["foo"] & 1]
[2 rows x 1 columns]
Traceback (most recent call last):
OK, let's try something else:
It looks like you have to use the original indices. But google sure can find
a way to get rid of these:
>>> odd = odd.reset_index(drop=True)
> Thanks a lot for any kind of help
More information about the Python-list