0

The 'gmv' column is string from dataframe 'df_g' ; It is number with comma (eg. "106,223")

I'm trying to select data with 2-conditions which are 'bigger than 1000000' and 'smaller than 10000' as int-type.

df_g[(df_g.gmv.str.replace(',', '').astype('int')<=10000) | (df_g.gmv.str.replace(',', '').astype('int')>=1000000)]

So I removed comma using 'replace' in order to change datatype as int.

But I think there would be better way, like not using <df_g.gmv.str.replace(',', '').astype('int')> twice or somthing.

Is there simple way to write this?

woohi
  • 3
  • 2
  • you can first save your series, `s = df_g.gmv.str.replace(',', '').astype('int')` ans use `s` in the conditions, or use `between` to get the values between the two values and reverse the condition with `~` – mozway Apr 20 '22 at 07:41
  • https://stackoverflow.com/a/22137890/3838691 – MaxNoe Apr 20 '22 at 07:44

0 Answers0