Filtering pandas in Python using 'where' -


I have a new question related to filtering pandes in Python.

My original data frame, DF, looks like it date currency 1Y 1Y1M 1Y2M 1Y3M 1Y4M 2013-09-25 EUR 0 0 0 0 0 0 9 - 26 EUR 0 0 0 2013-09-27 EUR 0 0 0 0 2013-09-28 Euro 0 0 0 0 2013-09-29 EUR 0 0 0 2013-09-25 USD 0 0 0 0 0 0 9 -26 USD 0 -2 -4 -8 -10 2013-09-27 USD 0 -1 -1 -6 -1 2013-09-28 USD 0 -3 -6-2 -6 2013-09- 29 USD 0 -5 -16 -7

What I would like to do, in some way to filter this data on 'USD', and all those who match the criteria Indicates available data. I want to change the original data (hence not copy), i.e. the resultant dataframe (i.e., df),

  date currency 1Y 1Y1M 1Y2M 1Y3M 1Y4M 2013-09-25 EUR 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2013-09-27 EUR 0 0 0 2013-09-28 Euro 0 0 0 0 9 9 9 -2 9 EUR 0 0 0 0 0 2013- 09-25 USD 0 0 0 2013-09-26 USD 0 2 4 8 10 2013-09-27 USD 0 1 1 6 1 2013-09-28 USD 3 6 2 6 2013-09 -29 USD 0 5 1 6 7 I tried to use the function as 'where' (with printing to see the effect)  
 < Code> mask = df ['currency'] .trank ('USD') print dfx [mask, '1 y 1m]] df Print data BREAKBB.ix [mask, '1Y1M']   

but print-results do not show any effect (DF [~ mask], -1 * DF, implicit = True).

Any information will be great!

  df.loc [df ['currency'] == 'USD', '1Y ':' 1Y4M '] * = -1   

yield date currency 1Y 1Y1M 1Y2M 1Y3M 1Y4M 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 -26 EUR 0 0 0 0 2 2013 -09-27 EUR 0 0 0 3 2013-09-28 EUR 0 0 0 0 4 2013-09-29 EUR 0 0 0 0 5 2013-09-25 USD 0 0 0 0 6 2013-09 -26 USD 0 2 4 8 10 7 2013-09-27 USD 0 1 1 6 1 8 2013-09-28 USD 3 3 6 2 6 9 2013-09-29 US Dollar 0 5 1 6 7 DF ['currency']. Str.contains ('USD') can be faster than df ['currency'] == 'USD' , I suggest using it later to guarantee that For you select only those rows where the currency is equal to the US dollar, in the past can be included rows whose currency contains USD I'm not sure it is possible , But why it is a threat.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -