0
import pandas as pd
s=pd.Series(data=[45,20,35,50,60],index=['a','b','c','d','e'])
s.drop("a",inplace=False)
print(s)
a    45
b    20
c    35
d    50
e    60
dtype: int64

s.drop("a",inplace=True)
    b    20
    c    35
    d    50
    e    60
    dtype: int64

when i am changing the value of inplace attribute to False, element at index "a" not deleted but when i am changing the value of inplace = True value at index "a" deleted. I did not understand how it works.

khelwood
  • 52,115
  • 13
  • 74
  • 94
manu
  • 33
  • 1
  • 6

1 Answers1

1

When you call drop with inplace=False, drop is returning a new Series rather than dropping the requested row in the existing Series. In other words:

x = s.drop("a",inplace=False)
print(s)
print()
print(x)

produces:

a    45
b    20
c    35
d    50
e    60
dtype: int64

b    20
c    35
d    50
e    60
dtype: int64

where:

x = s.drop("a",inplace=True)
print(s)
print()
print(x)

produces:

b    20
c    35
d    50
e    60
dtype: int64

None
CryptoFool
  • 17,917
  • 4
  • 23
  • 40