简体   繁体   English

如何从 python pandas 列中删除最后一个字母

[英]How to remove last letters from column python pandas

I got the following dataframe我得到了以下 dataframe

Initial最初的
MH. MH。
TH TH

How can i remove the.. from MH.我怎样才能从 MH 中删除.. to MH到MH

Use Series.str.replace with escape .使用Series.str.replace和 escape . :

df['Initial'] =  df['Initial'].str.replace(r'\.+', ".")

You can also use string indexing,您还可以使用字符串索引,

string[:-1]

In your case,在你的情况下,

"M.H.."[:-1]

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM