3 回答
TA贡献1801条经验 获得超8个赞
Series.str.replace
与正则表达式模式和替换 lambda 函数一起使用。您可以测试正则表达式模式here
:
df['Test'] = df['Test'].str.replace(r'((?<=\b)\S)', lambda x: x.group(1).lower())
结果:
Test
0 there is a cat uNDER the table
1 the pen is working wELL.
TA贡献1840条经验 获得超5个赞
构建您的解决方案:
df["Test"] = [" ".join(entry[0].lower() + entry[1:]
for entry in word.split())
for word in df.Test]
df
Test
0 there is a cat uNDER the table
1 the pen is working wELL.
TA贡献1797条经验 获得超6个赞
以下
import pandas as pd
def uncapitalise(x):
words = x.split(' ')
result = []
for word in words:
print(word)
if word:
word = word[0].lower() + word[1:]
result.append(word)
return ' '.join(result)
data = ['Test','There is a cat UNDER the table ','The pen is working WELL.']
df = pd.DataFrame(data)
df[0] = df[0].apply(uncapitalise)
print(df)
添加回答
举报