0

I have two pandas series as shown below,

df1 = 
index                  value 
2014-05-23 00:00:00      NaN
2014-05-23 01:00:00      NaN
2014-05-23 02:00:00     0.00
2014-05-23 03:00:00      NaN
...
2018-01-01 05:00:00     0.59
2014-01-01 06:00:00     0.43
2014-01-01 07:00:00     1.00

and df2

df2 =
index                  value     
2014-05-23 00:00:00      9.9
2014-05-23 01:00:00       23
2014-05-23 02:00:00      4.3
2014-05-23 03:00:00     10.6
...
2018-01-01 05:00:00      8.3
2014-01-01 06:00:00      0.3
2014-01-01 07:00:00      0.0

and relationship between df1 and df2 is one by one , I would like to plot the figure with x value (df1) and y value (df2) but only choose the value in df1 bigger than 0 and smaller than 1 (directly ignore the NaN).

I just know how to find the value with one condition

df.loc[lambda df: df != 1]   or   df.loc[lambda df: df != 0]  

but it doesn't work when I write

df.loc[lambda df: df != 1 and != 0]   or   df.loc[lambda df: 1> df > 0]

and I don't know how to match the values found in df1 to df2, in order to plot it.

Anyone have ideas? Thanks in advance !

Chi
  • 187
  • 3
  • 14
  • Are you asking how to merge the two dataframes or asking how to use the or condition, which uses `|` as the "reserved word", or both? I feel like merging these dataframes might be the best option – MattR Apr 04 '18 at 20:01
  • I can't tell if your data frames are actually series. They don't look like data frames. I see two columns, but I don't see the headers. If they are series, that first column is an index. Is that what it is? – piRSquared Apr 04 '18 at 20:06
  • 1) You don't need to use lambdas here. `df.loc[df != 1]` would work just fine as well. If they can be aligned somehow (you say there is one-to-one relationship so they can be) you can use `df1.loc[condition_regarding_df2]` for example `df1.loc[df2 > 0]`. If you want to combine multiple conditions use bitwise operators and wrap the conditions in parentheses: `df1.loc[(df2 > 0) & (df2 < 5)]`. – ayhan Apr 04 '18 at 20:09
  • @MattR I have solved it, and indeed merging the data is the best option to deal with this problem, thanks ! – Chi Apr 04 '18 at 20:45
  • @piRSquared sorry I forgot to indicate the index. – Chi Apr 04 '18 at 20:47
  • @ayhan thanks it works and I have solved the problem ! – Chi Apr 04 '18 at 20:48

0 Answers0