0

Trying to run a code in the jupyter notebook:

location.str.split("\n",expand=True)\
.drop(columns = 1, inplace = True)

but failing to get the desired result. Nothing is happennig, not even the error is popping up.

Whereas, the below code is giving me the desired result:

location = location.str.split("\n",expand=True)\
.drop(columns = 1)

Just want to know the issue!

Just for the reference -

Location used to be a list. Later got converted into a Series. Got splited up using str.split().

if I'm using the code in different code blocks, then it is working fine -

location.str.split("\n",expand=True)
location.drop(columns = 1, inplace=True)
  • Here `drop(inplace=True)` applies to a temporary dataframe that is not accessible in the following code. Using `inplace=True` makes sense only when you apply a method to a pandas object you have a handle to access it in the following code. – Dima Chubarov Nov 05 '22 at 11:01

1 Answers1

2

The expressionlocation.str.split("\n",expand=True)\ .drop(columns = 1, inplace = True) in fact do not return value, because the parameter inplace is set to True. If you remove inplace=True or set inplace=False, then it returns value, which could be what you want.

LEGION GREEN
  • 151
  • 6
  • For more information about `inplace` parameter, you can refer to [this post](https://stackoverflow.com/questions/43893457/understanding-inplace-true-in-pandas?rq=1). Hope it will help. – LEGION GREEN Nov 05 '22 at 10:59
  • inplace=True is not even making changes to the original dataframe. The whole is being avoided by the compiler. – Shubham Bhardwaj Nov 05 '22 at 16:16