简体   繁体   English

如何删除 python 中 pandas df 列中某个字符之前的所有字符

[英]How to remove all characters before a certain character in pandas df column in python

How to remove all the characters before " \ "如何删除“\”之前的所有字符

column1

absc \ efgcvc \ Hello
hij \ klsm \ Hey
qssdrs \ uv \ yellow

I would like to have the output as below:我想要 output 如下:

column1

Hello
Hey
Yellow

Using str.replace we can try:使用str.replace我们可以尝试:

df["column1"] = df["column1"].str.replace(r'^.*\\\s*', '')
df = pd.DataFrame({'column1':['absc \ efgcvc \ Hello','hij \ klsm \ Hey','qssdrs \ uv \ yellow']})
df2 = pd.DataFrame(columns=['column1'])
for i in range (0,3,1):
    a = df.iloc[i,0];
    a = (a.split(' \ '))
    df2 = df2.append({'column1': a[2]}, ignore_index=True)

print(df2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pandas:删除 dataframe 列中特定字符之前的所有字符 - Pandas: Remove all characters before a specific character in a dataframe column 如何删除熊猫列中包括某个字符在内的所有字符? - How can one remove all characters including and after a certain character in a pandas column? Pandas:删除特定字符重复4次的dataframe列中特定字符(最后一个特定字符)之前的所有字符 - Pandas: Remove all characters before a specific character (last specific character) in a dataframe column that specific character is repeated 4 times 如何使用 Python 3 删除某个字符后的所有字符 - How to remove all characters after a certain character using Python 3 如何删除 Python 中特定字符之前的所有字符? - How to remove all characters before a specific character in Python? Python、Pandas、df 2 部分问题:1. 如何根据特定条件将列添加到列表中 2. 如何从 df 中删除这些列 - Python, Pandas, df 2 part question: 1. how to add a column into a list based of a certain condition 2. how to remove those columns from df 如何删除 Python 中某个字符之前的所有内容 - How to remove everything before certain character in Python 如何删除 df 列 python 中最后一个句点之后的字符? - How to remove characters after last period in df column python? 如何在Python中删除冒号之前的所有字符 - How to remove all characters before colon in python 如何去除Pandas DF中的特殊字符? - How to remove special characters from Pandas DF?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM