dataframe.rename_axis()
viene utilizzato per rinominare gli assi o le colonne dell’indice in un dataframe .
Sintassi: DataFrame.rename_axis (mapper, axis = 0, copy = True, inplace = False)
Parametri:
mapper : [scalare, simile a un elenco, facoltativo] Valore per impostare l’attributo del nome dell’asse.
axis: int o string, default 0
copy: [iboolean, default True] Copia anche i dati sottostanti
inplace : booleano, predefinito Falso
Restituisce: rinominato: tipo di chiamante o Nessuno se presente = Vero
Per collegarsi a il file CSV utilizzato nel codice, fai clic qui
Esempio n. 1: sostituisci il comando Boston Celtics con Omega Warrior nel file nba.csv
# import pandas as pd < p> import panda come pd # Crea frame di dati da file CSV df = pd.read_csv ( "nba.csv" ) p> # Stampa le prime 10 righe # dataframe per il rendering df [: 10 ] td> |
Output:
Modificheremo gli indici di riga e raddoppieremo il valore.
# questo aumenterà il valore dell’indice di riga di due volte df .rename_axis ( lambda x : x * 2 , asse = "indice" ) |
tbody>
Output:
Esempio n. 2.
strong> Modifica del nome della colonna
< tbody> # importa panda come pd import panda come pd # Crea frame ma dati da un file CSV df = pd.read_csv ( "nba.csv" ) # questo aggiungerà & # 39; _X & # 39; alla fine di ogni nome di colonna df.rename_axis ( lambda x: x + " _ X " , asse = "colonne" ) td > |
Output:
Python | Pandas dataframe.rename_axis () Python functions: Questions
Python | Pandas dataframe.rename_axis () rename: Questions
Shop
Best laptop for Fortnite
$
Best laptop for Excel
$
Best laptop for Solidworks
$
Best laptop for Roblox
$
Best computer for crypto mining
$
Best laptop for Sims 4
$
Best laptop for Zoom
$499
Best laptop for Minecraft
$590
Latest questions
NUMPYNUMPY
psycopg2: insert multiple rows with one query
12 answers
NUMPYNUMPY
How to convert Nonetype to int or string?
12 answers
NUMPYNUMPY
How to specify multiple return types using type-hints
12 answers
NUMPYNUMPY
Javascript Error: IPython is not defined in JupyterLab
12 answers
Wiki
Python OpenCV | cv2.putText () method
numpy.arctan2 () in Python
Python | os.path.realpath () method
Python OpenCV | cv2.circle () method
Python OpenCV cv2.cvtColor () method
Python - Move item to the end of the list
time.perf_counter () function in Python
Check if one list is a subset of another in Python
Python os.path.join () method