dataframe重命名
生活随笔
收集整理的這篇文章主要介紹了
dataframe重命名
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.讀取文件的時候重命名 names = new_col,可以在讀取文件的時候,給出新列名。
new_col = ['new1', 'new2',... , 'newn']
pd.read_csv('data', names = new_col, header=0) ?
2.全部重命名 columns = new_columns,新列名的長度必須與舊列名一致
new_col = ['new1', 'new2',... , 'newn'] dataframe.columns = new_col
?
3.部分重命名columns = dict,使用字典類型的數據對列進行重命名。
dataframe.rename(columns = {"old_name": "new_name"})
dataframe.rename(columns = {"old1": "new1", "old2":"new2"}, inplace=True) ?
4.使用str.replace
dataframe.columns = dataframe.columns.str.replace('' '', ''_'') ?
總結
以上是生活随笔為你收集整理的dataframe重命名的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dataframe多列合并成一列
- 下一篇: bert as service