[英]Cut word from column and paste to new column
On printing AllTogetherNoNan_df.head() 在打印AllTogetherNoNan_df.head()
0 Null Null Null Misty Morn Null Horsefen Road Great Yarmouth NR29 5QJ Ludham Null
1 Null Null 16 St Catherines Way Null Gorleston Norfolk NR31 7QB Great Yarmouth Null
3 Null Null 21 Links Road Null Gorleston Norfolk NR31 6JP Great Yarmouth Null
4 Null Null Null Ground Floor Null Back Flat Gorleston NR31 6AL 15 Upper Cliff Road Null
6 Null Null 3 The Boulters Null Gorleston Norfolk NR31 6TF Great Yarmouth Null
I would like to cut county Norfolk and paste it to new column 'County' 我想削减诺福克县并将其粘贴到新栏目“县”
You could do it in two steps 你可以分两步完成
Copy Over 'Norfolk', if column string has 'Norfolk' substring 如果列字符串包含'Norfolk'子字符串,则复制'Norfolk'
Strip original column. 剥离原始列。
def copy(row): if 'Norfolk' in row[col_index_in_question]: return 'Norfolk' def strip(row): return row[col_index_in_question].replace('Norfolk', '') df['County'] = df.apply(copy, axis=1) df[col_index_in_question] = df.apply(strip, axis=1)
Replace col_index_in_question
with you column index 将
col_index_in_question
替换为列索引
But more importantly if it's a specific formatted address that you want to parse, you can use this Python Parser Lib 但更重要的是,如果它是您要解析的特定格式化地址,则可以使用此Python Parser Lib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.