[英]How to remove last letters from column python pandas
I got the following dataframe我得到了以下 dataframe
Initial![]() |
---|
MH. ![]() |
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.