-1

I'm currently reading Python for Data Analysis by Wes. There's a line of code in the book which assign a inplace rename of a df to underscore. Why? And there's also a comment atop that says Always returns a reference to a DataFrame. What does it mean?

# Always returns a reference to a DataFrame
In [151]: _ = data.rename(index={'OHIO': 'INDIANA'}, inplace=True)
underhill
  • 35
  • 4
  • Since within `rename`, you specified `inplace=True`, that means the dataframe is changed inplace without explicit re-assignment. Usually you don't need the `_ = ` part and only need to do `data.rename(index={'OHIO': 'INDIANA'}, inplace=True)` and it will return `None`, which is not to be used anyways. In general when you assign something to `_`, you are telling people that you are not using the returned value and it can be safely ignored. – TYZ Feb 24 '21 at 14:49

1 Answers1

0

I think this answer might help you SO_link I would add that in your case the use of the special variable '_' was not necessary but maybe a way from the author to make you wonder what it is...

thesylio
  • 144
  • 7