Does pandas Series.update() not really allow the index parameter?
Question:
In Pandas documentation for their Series.update function, they give the following example
s = pd.Series(['a', 'b', 'c'])
s.update(pd.Series(['d', 'e'], index=[0, 2]))
s
0 d
1 b
2 e
dtype: object
https://pandas.pydata.org/docs/reference/api/pandas.Series.update.html
But when I recreate a similar example, I get a TypeError that says
Series.update() got an unexpected keyword argument 'index'
My Try, using pandas version 1.4.3:
INPUT:
ser = pd.Series(['a', 'b', 'c'])
print(ser)
OUTPUT:
0 a
1 b
2 c
dtype: object
INPUT:
replacer = pd.Series(['x','z'])
print(replacer)
OUTPUT:
0 x
1 z
dtype: object
INPUT:
ser.update(replacer, index=[0, 1])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
c:Userssomebodyprojectsmy_projectmy_notebook.ipynb Cell 11 in <cell line: 1>()
----> 1 ser.update(replacer, index=[0, 1])
TypeError: Series.update() got an unexpected keyword argument 'index'
Is this ‘index’ keyword parameter just not implemented or is there something very obvious that I am not doing?
Answers:
I assume it’s a documentation bug. In the source code, the function is defined as
def update(self, other) -> None:
It doesn’t even take an *args
to allow for other options. You might file a bug report.
This is not a bug. Look carefully at the brackets:
s.update(pd.Series ( [‘d’, ‘e’], index=[0, 2] ) )
They cover both the index and the "d" and "e". In your code you only bracketed the two letters without the index no. inside as well.
As @Tim_Roberts has mentioned, this is from the source codeand the function is:
def update(self, other) -> None:
This function has no *args
and therefore you cannot simply use index
on its own in the function.
In Pandas documentation for their Series.update function, they give the following example
s = pd.Series(['a', 'b', 'c'])
s.update(pd.Series(['d', 'e'], index=[0, 2]))
s
0 d
1 b
2 e
dtype: object
https://pandas.pydata.org/docs/reference/api/pandas.Series.update.html
But when I recreate a similar example, I get a TypeError that says
Series.update() got an unexpected keyword argument 'index'
My Try, using pandas version 1.4.3:
INPUT:
ser = pd.Series(['a', 'b', 'c'])
print(ser)
OUTPUT:
0 a
1 b
2 c
dtype: object
INPUT:
replacer = pd.Series(['x','z'])
print(replacer)
OUTPUT:
0 x
1 z
dtype: object
INPUT:
ser.update(replacer, index=[0, 1])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
c:Userssomebodyprojectsmy_projectmy_notebook.ipynb Cell 11 in <cell line: 1>()
----> 1 ser.update(replacer, index=[0, 1])
TypeError: Series.update() got an unexpected keyword argument 'index'
Is this ‘index’ keyword parameter just not implemented or is there something very obvious that I am not doing?
I assume it’s a documentation bug. In the source code, the function is defined as
def update(self, other) -> None:
It doesn’t even take an *args
to allow for other options. You might file a bug report.
This is not a bug. Look carefully at the brackets:
s.update(pd.Series ( [‘d’, ‘e’], index=[0, 2] ) )
They cover both the index and the "d" and "e". In your code you only bracketed the two letters without the index no. inside as well.
As @Tim_Roberts has mentioned, this is from the source codeand the function is:
def update(self, other) -> None:
This function has no *args
and therefore you cannot simply use index
on its own in the function.