Closed
Description
Pandas version checks
- I have checked that the issue still exists on the latest versions of the docs on
main
here
Location of the documentation
https://pandas.pydata.org/docs/reference/api/pandas.Series.rename.html
Documentation problem
Documentation says only inplace
keyword is used, but actually other keywords from DataFrame.rename
are valid
copy
import pandas as pd
s = pd.Series(["foo", "bar"])
shallow = s.rename({1: 9}, copy=False)
s[0] = "foobar"
print(s)
# 0 foobar
# 1 bar
# dtype: object
print(shallow)
# 0 foobar
# 9 bar
# dtype: object
errors
import pandas as pd
s = pd.Series(["foo", "bar"])
s.rename({2: 9}, errors="raise") # This raises
level
import pandas as pd
arrays = [
["bar", "bar", "baz", "baz"],
["one", "two", "baz", "baz"],
]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=["first", "second"])
s = pd.Series([0, 1, 2, 3], index=index)
print(s)
# first second
# bar one 0
# two 1
# baz baz 2
# baz 3
# dtype: int64
print(s.rename({"baz": "buz"}, level=1))
# first second
# bar one 0
# two 1
# baz buz 2
# buz 3
# dtype: int64
Suggested fix for documentation
Document the above args - or just mention Series.rename
accepts all args of DataFrame.rename
except labels
and columns