溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么重命名Pandas DataFrame中的列名

發(fā)布時間:2021-11-30 10:29:44 來源:億速云 閱讀:477 作者:小新 欄目:大數(shù)據(jù)

這篇文章主要介紹怎么重命名Pandas DataFrame中的列名,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

 
入門示例

怎么重命名Pandas DataFrame中的列名

怎么重命名Pandas DataFrame中的列名

怎么重命名Pandas DataFrame中的列名

怎么重命名Pandas DataFrame中的列名

上述代碼:


# ## 如何重命名pandas dataframe中的列名字# In[32]:import pandas as pd# In[33]:data = pd.read_csv('ufo.csv')# ## 查看data的類型# In[34]:type(data)# ## 顯示前幾條數(shù)據(jù)# In[35]:data.head()# ## 打印所有的列名# In[36]:data.columns# ## 使用rename()進行重命名列明# In[37]:data.rename(columns={'Shape Reported':'Shape_Reported',\  'Colors Reported':'Colors_Reported'},inplace=True)# ## 打印重命名后的列# In[38]:data.columns# ## 定義一個list 整體替換列名# In[39]:data_cols= ['city', 'colors reported', 'shape reported',\ 'state', 'time']# In[40]:data.columns = data_cols# In[41]:data.head()# ## 讀取數(shù)據(jù)時指定列名# In[42]:data = pd.read_csv('ufo.csv',names= data_cols,header=0)data.head()# In[43]:data.columns# ## 使用replace()修改列名# In[44]:data.columns = data.columns.str.replace(' ','_')# In[45]:data.columns

以上是“怎么重命名Pandas DataFrame中的列名”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI