3 回答

TA貢獻1801條經(jīng)驗 獲得超8個贊
Series.str.replace
與正則表達式模式和替換 lambda 函數(shù)一起使用。您可以測試正則表達式模式here
:
df['Test']?=?df['Test'].str.replace(r'((?<=\b)\S)',?lambda?x:?x.group(1).lower())
結(jié)果:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Test
0? there is a cat uNDER the table
1? ? ? ? the pen is working wELL.

TA貢獻1840條經(jīng)驗 獲得超5個贊
構(gòu)建您的解決方案:
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條經(jīng)驗 獲得超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)
添加回答
舉報