“PANDAS Ubah Nama Kolom” Kode Jawaban

Ganti nama kolom panda

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
Charred Dolphin

mengganti nama header Pandasd

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

Ganti nama kolom DF

import pandas as pd
data = pd.read_csv(file)
data.rename(columns={'original':'new_name'}, inplace=True)
Cozy Dev

Python: Ubah nama kolom

df = df.rename(columns = {'myvar':'myvar_new'})
Andrea Perlato

Kolom Rename PANDAS

df.rename(columns={"old_col1": "new_col1", "old_col2": "new_col2"}, inplace=True)
Exuberant Eland

PANDAS Ubah Nama Kolom

# Geopandas use the same rename function as Pandas.

import pandas as pd

df = pd.GeoDataFrame({'x':['John', 'Doe', 'Paul'], 
        'y':[22, 31, 15],
        'z':[[-45.23332,34.23556], [-45.32565,34.49347], [-45.27648,34.45284]]
        })
columns_Name = {'x': 'name', 'y': 'age', 'z': 'location'}
df = df.rename(columns = columns_Name)
df
   name  age               location
0  John   22  [-45.23332, 34.23556]
1   Doe   31  [-45.32565, 34.49347]
2  Paul   15  [-45.27648, 34.45284]

# When you want the change to be implicitly saved
columns_Name = {'x': 'name', 'y': 'age', 'z': 'location'}
df.rename(columns = columns_Name, inplace=True)
Intempestive Al Dente

Jawaban yang mirip dengan “PANDAS Ubah Nama Kolom”

Pertanyaan yang mirip dengan “PANDAS Ubah Nama Kolom”

Lebih banyak jawaban terkait untuk “PANDAS Ubah Nama Kolom” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya