pandas alias别名、列重命名

刘超 7天前 ⋅ 518 阅读   编辑
# Import pandas package 
import pandas as pd 
   
# Define a dictionary containing ICC rankings 
rankings = {
	'test': ['India', 'South Africa', 'England', 'New Zealand', 'Australia'], 
	'odi': ['England', 'India', 'New Zealand', 'South Africa', 'Pakistan'], 
	't20': ['Pakistan', 'India', 'Australia', 'England', 'New Zealand']
} 
   
# Convert the dictionary into DataFrame 
rankings_pd = pd.DataFrame(rankings) 
   
# Before renaming the columns 
print(rankings_pd.columns) 
   
rankings_pd.rename(columns = {'test':'TEST', 'odi':'ODI', 't20':'T20'}, inplace = True) 
   
# After renaming the columns 
print(rankings_pd.columns) 

注意:本文归作者所有,未经作者允许,不得转载

全部评论: 0

    我有话说: