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
  • 55,782
  • 14
  • 81
  • 108
manu
  • 33
  • 2
  • 8

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
  • 21,719
  • 5
  • 26
  • 44