แทนที่คอลัมน์รายชื่อ pandas

รหัสตัวอย่าง

32
0

N

df.rename(columns={'oldName1': 'newName1',
                   'oldName2': 'newName2'},
          inplace=True, errors='raise')
# Make sure you set inplace to True if you want the change
# to be applied to the dataframe
26
0

N

>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
>>> df.rename(columns={"A": "a", "B": "c"})
   a  c
0  1  4
1  2  5
2  3  6
16
0

N

# Basic syntax:
# Assign column names to a Pandas dataframe:
pandas_dataframe.columns = ['list', 'of', 'column', 'names']
# Note, the list of column names must equal the number of columns in the
# 	dataframe and order matters

# Rename specific column names of a Pandas dataframe:
pandas_dataframe.rename(columns={'column_name_to_change':'new_name'})
# Note, with this approach, you can specify just the names you want to
# 	change and the order doesn't matter

# For rows, use "index". E.g.:
pandas_dataframe.index = ['list', 'of', 'row', 'names']
pandas_dataframe.rename(index={'row_name_to_change':'new_name'})
13
0

N

df.rename(columns={"old_col1": "new_col1", "old_col2": "new_col2"})
9
0

N

df.rename(columns={"A": "a", "B": "b", "C": "c"},
errors="raise", inplace=True)
1
0

N

#df.rename() will only return a new df with the new headers
#df = df.rename() will change the heders of the current dataframe 
df = df.rename(columns={"old_col1": "new_col1", "old_col2": "new_col2"})

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังหน้ากับตัวอย่างอยู่ในหมวดหมู่