简体   繁体   English

从列中删除单词并粘贴到新列

[英]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  

Excel File Excel文件

I would like to cut county Norfolk and paste it to new column 'County' 我想削减诺福克县并将其粘贴到新栏目“县”

You could do it in two steps 你可以分两步完成

  1. Copy Over 'Norfolk', if column string has 'Norfolk' substring 如果列字符串包含'Norfolk'子字符串,则复制'Norfolk'

  2. 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.

相关问题 如何从一列中剪切数据并粘贴到 Python -> Pandas 中的新列中? - How to cut data from one column and paste into a new column in Python -> Pandas? 检查列是否包含nan,剪切并粘贴到下一列 - Check if the column contains nan, cut and paste to next column 如何从一列的一行中删除特定单词并使用 python 将删除的 substring 粘贴到另一列 - how to remove a specific word from a row of one column and paste the removed substring to another column using python 如何将制表符分隔表中的值粘贴到与第一个文件中第1列中的单词匹配的第二个文件中 - How to paste values from a tab delimited table into a second file matching a word in column 1 from the first file 用列表中的单词替换句子中的单词并复制列中的新句子 - Replace a word in a sentence with words from a list and copying the new sentences in a column 熊猫-在字符串列中某个字符之后“剪切”所有内容并将其粘贴到列的开头 - Pandas - 'cut' everything after a certain character in a string column and paste it in the beginning of the column 搜索列,如果值不是所有数字,则将值剪切并粘贴到同一行的另一列 python pandas - Search column, if value is not all digits, then cut&paste value to another column same row python pandas 将数组列分解为新的子列,这些子列包含从父列中切出的元素 - Breaking down array columns into new sub-columns containing elements cut out from the parent column 将新列添加到Pandas DataFrame,并用同一df的另一列填充第一个单词 - Add new column to Pandas DataFrame and fill with first word from another column from same df 从一个数据框中复制数据并将与该值对应的列名粘贴到新数据框中 - Copy data from one data frame and paste in column name corresponding to that value in a new Data Frame
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM