kieferk / dfply

dplyr-style piping operations for pandas dataframes
GNU General Public License v3.0
889 stars 103 forks source link

use mask for column names with blank #52

Open steer629 opened 6 years ago

steer629 commented 6 years ago

for some reasons, I have a very complicate excel be read into pandas, some column names are with blank, i.e "Commercial Project-ID", target_data_frame= orginal_data_frame >> mask(X.['Commercial Project-ID']==0) or target_data_frame= orginal_data_frame >> mask(X.'Commercial Project-ID'==0) or target_data_frame= orginal_data_frame >> mask(X.Commercial Project-ID==0)

either way, not work of course I can remove the blank before the filter, but I am wondering, if there are better way to do

svenski commented 6 years ago

In addition, if you happen to have a column called isin which is a pandas function, the mask call doesn't work. It might not be exactly the same issue but could possibly be solved using a similar method as above.

Here is a minimal example which yields an error:AttributeError: 'NotImplementedType' object has no attribute 'dtype'

    pp = pd.DataFrame( {'isin': ['a','b']})
    pp >> mask(X.isin == 'b')