In :char_df‘’Loan_Title‘.
类别:“债务合并”、“信用卡再融资”、“住房改善”、“信贷整合”、“绿色贷款”、“其他”、“搬家和搬迁”、“信用卡”、“医疗费用”、“再融资”、“信用卡合并”、“贷款俱乐部”、“债务合并贷款”、“主要购买”、“假期”、“业务”、“信用卡支付”、“信用卡”、“再投资”、“个人贷款”、“cc refi”,“合并”、“医疗”、“贷款1”、“合并”、“信用卡合并”、“汽车融资”、“债务”、“购房”、“自由”、“合并”、“摆脱债务”、“合并贷款”、“部门合并”、“个人”、“信用卡”、“浴室”、“再融资”、“信用卡贷款”、“住房”、“2013年债务合并”、“债务贷款”、“cc再融资”,“家”、“cc整固”、“信用卡再融资”、“信用贷款”、“还贷”、“账单合并”、“信用卡付款”、“信用卡还清”、“免债务”、“我的贷款”、“信用卡还清”、“我的贷款”、“账单偿还”、“cc-再融资”、“债务减免”、“医疗贷款”、“婚礼贷款”、“信用”、“偿还账单”、“再融资贷款”,“债务偿还”、“汽车贷款”、“偿还”、“池”、“信用偿还”、“信用卡再融资贷款”、“cc贷款”、“无债务”、“conso”、“住房改善贷款”、“贷款整合”、“贷款”、“救济”、“cc”、“贷款1”、“前进”、“住房贷款”、“票据”、“dtype=object”)
单位:char_df=char_df.replace(“债务合并”、“债务合并贷款”、“部门合并”、“2013年债务合并”、“dept_consolidation”) char_df =char_df.replace(“个人”、“个人贷款”、“personal_loan”) char_df =char_df.replace(“信用卡再融资”、“credit_card_refinance”)
发布于 2021-12-08 16:02:12
IIUC (很难阅读)您可以尝试以下几种方法:
import pandas as pd
# will use regex pattern as keys and replace string as value
patterns = {
r'dept consolidation.*': 'dept_consolidation',
r'personal.*': 'personal_loan',
r'credit card.*': 'credit_card_refinance'
}
df['Loan_Title'] = df['Loan_Title'].replace(regex=patterns)https://stackoverflow.com/questions/70277650
复制相似问题