替换 DF 列中的句点 [英] Replacing Periods in DF's Columns

查看:41
本文介绍了替换 DF 列中的句点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种有效的方法来替换 Pandas 数据帧中的句点,而不必遍历每一行并在该行上调用.replace().

I was wondering if there was an efficient way to replace periods in pandas dataframes without having to iterate through each row and call.replace() on the row.

import pandas as pd 
df = pd.DataFrame.from_dict({'column':['Sam M.']})
df.column = df.column.replace('.','')

print df

结果

   column

0  None

想要的结果

   column

0  Sam M

推荐答案

df['column'].str.replace('.', '', regex=False)

0    Sam M
Name: column, dtype: object

这篇关于替换 DF 列中的句点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆