Pandas DataFrame.rename unexpected axis argument when using mapper

Following the pandas docs , I tried the following (verbatim from the docs):

df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
df.rename(str.lower, axis='columns')

but i get an error

TypeError: rename () received an unexpected axis argument

I also tried

df.rename(mapper=str.lower, axis='columns')

but then I get:

TypeError: rename () received an unexpected keyword argument "mapper"

Am I looking at an old version of documents?

+4
source share
2 answers

Am I looking at an old version of documents?

No, quite the opposite. You are viewing the latest version ( 0.21currently). I am sure you have an older version of pandas.

, axis /, index=... columns=.... , API-, . rename .

, , , , mapper axis 0.21.

, -

df.columns = df.columns.str.lower()

df = df.rename(columns=dict(zip(df.columns, df.columns.str.lower())))
+6

, columns:

df.rename(columns={c:c.lower() for c in df.columns})

, !

0

Source: https://habr.com/ru/post/1690727/


All Articles