Python 通过行进行迭代以取消大写字符串和单词

Python 通过行进行迭代以取消大写字符串和单词,python,pandas,dataframe,Python,Pandas,Dataframe,我想知道如何转换本栏中每个单词的第一个字母: Test There is a cat UNDER the table The pen is working WELL. 放入小写,以便 Test there is a cat uNDER the table the pen is working wELL. 对于字符串,可以使用以下代码: " ".join(i[0].lower()+i[1:] for i in line.split(" &quo

我想知道如何转换本栏中每个单词的第一个字母:

Test
There is a cat UNDER the table 
The pen is working WELL.
放入小写,以便

Test
    there is a cat uNDER the table 
    the pen is working wELL.
对于字符串,可以使用以下代码:

" ".join(i[0].lower()+i[1:] for i in line.split(" "))
如何在列中的行中重复此操作?

与正则表达式模式和替换lambda函数一起使用。您可以测试正则表达式模式:

下面


构建您的解决方案:

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.

关于删除的问题,请看
                             Test
0  there is a cat uNDER the table
1        the pen is working wELL.
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)
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.