dimanche 23 avril 2017

Python If Else Segmentation 'Invalid Type Comparison' Error in Dataframe

I have a sample dataframe (df_merged_1) shown below:

enter image description here

The Revenue column is a float64 dtype. I want to create a new column called 'Revenue_Segment'. This is what I want the end result to look like:

enter image description here

Below is the code I used to segment:

if df_merged_1['Revenue'] >= 0 and df_merged_1['Revenue'] <= 2200:
    df_merged_1['AUM_Segment'] == 'test1'
else:
    df_merged_1['AUM_Segment'] == 'test0'

But the code is not working ... I get the following error:

TypeError: invalid type comparison

Any help is greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire