程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Pandas Skills] Replace the value in a field

編輯:Python

Question: Replace the values ​​in the field 'Channel Name' with the following results

'FOX CHINA-DF' is replaced by 'FOC',

'FOX CZECH-DF' is replaced by 'FCZ',

'FOX TEXAS-DF' replaced by 'FTX'

'FOX JUAREZ' replaced by 'FJZ',

'FOX JUAREZ-DF' replaced by 'FJZ DF'

import pandas as pddf = pd.DataFrame([[1,'FOX CHINA-DF'],[2,'FOX CZECH-DF'],[3,'FOX TEXAS-DF'],[4,'FOX JUAREZ'],[5,'FOX JUAREZ-DF']],columns = ['P/N','Channel Name'])# Use the replace method to replace the value in the 'Channel Name' fielddf = df.replace({'FOX CHINA-DF':'FOC', 'FOX CZECH-DF':'FCZ', 'FOX TEXAS-DF':'FTX','FOX JUAREZ':'FJZ', 'FOX JUAREZ-DF':'FJZ DF'})

df

Replaced df


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved