“Pandas Rename Column by Dictionary” Kode Jawaban

Pandas mengganti nama Kamus Nilai Kolom

df['col1'].map(di)       # note: if the dictionary does not exhaustively map all
                         # entries then non-matched entries are changed to NaNs
Calm Crab

Pandas Rename Column by Dictionary

# import pandas
import pandas as pd
 
# create data frame
df = pd.DataFrame({'First Name': ["Mukul", "Rohan", "Mayank",
                                  "Vedansh", "Krishna"],
                    
                   'Location': ["Saharanpur", "Rampur", "Agra",
                                "Saharanpur", "Noida"],
                    
                   'Pay': [56000.0, 55000.0, 61000.0, 45000.0, 62000.0]})
 
# print original data frame
display(df)
 
# create a dictionary
# key = old name
# value = new name
dict = {'First Name': 'Name',
        'Location': 'City',
        'Pay': 'Salary'}
 
# call rename () method
df.rename(columns=dict,
          inplace=True)
 
# print Data frame after rename columns
display(df)
Nutty Nightingale

Pandas mengganti nama Kamus Nilai Kolom

df['col1'].map(di).fillna(df['col1'])
Calm Crab

Jawaban yang mirip dengan “Pandas Rename Column by Dictionary”

Pertanyaan yang mirip dengan “Pandas Rename Column by Dictionary”

Lebih banyak jawaban terkait untuk “Pandas Rename Column by Dictionary” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya