0
 i += 1

can be used to shorten

 i = i + 1 

Now, I really want some

.=

operator to shorten painfull stuff like

some_long_df_name['some_equally_long_column_name'] = some_long_df_name['some_equally_long_column_name'].do_method()

into

some_long_df_name['some_equally_long_column_name'] .= do_method()

  1. I know that i+=1 is not exactly the same as i = i+1 (inplace vs reassigning, see also the answer on this SO post What is the difference between i = i + 1 and i += 1 in a 'for' loop?)
  2. I looked at the
.__iXXX__

methods from python https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types and couldnt find what I was looking for.

So mostly I am looking for a good explanation why this operator/method isnt there, or some python hack/trick to overload/construct this operator myself.

Thanks !!

Rens
  • 177
  • 9

1 Answers1

0

I've never heard of such an operator but you could just do something like this to get rid of long names:

col = 'some_equally_long_column_name'

some_long_df_name[col] = some_long_df_name[col].do_method()

Also many pandas in-built functions have inplace parameter that will modify df in-place if set to True.

NotAName
  • 3,821
  • 2
  • 29
  • 44