我有一个如下所示的熊猫数据框。我想将所有文本转换为小写。我怎样才能在Python中做到这一点?
\n\n\n\n\n数据框样本
\n
[Nah I don't think he goes to usf, he lives around here though] \n\n[Even my brother is not like to speak with me., They treat me like aids patent.] \n\n[I HAVE A DATE ON SUNDAY WITH WILL!, !] \n\n[As per your request 'Melle Melle (Oru Minnaminunginte Nurungu Vettam)' has been set as your callertune for all Callers., Press *9 to copy your friends Callertune] \n\n[WINNER!!, As a valued network customer you have been selected to receivea \xc2\xa3900 prize reward!, To claim call 09061701461., Claim code KL341., Valid 12 hours only.]\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n我尝试过的
\n
def toLowercase(fullCorpus):\n lowerCased = [sentences.lower()for sentences in fullCorpus['sentTokenized']]\n return lowerCased\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n我收到这个错误
\n
lowerCased = [sentences.lower()for sentences in fullCorpus['sentTokenized']]\nAttributeError: 'list' object has no attribute 'lower'\nRun Code Online (Sandbox Code Playgroud)\n
这很容易:
df.applymap(str.lower)
Run Code Online (Sandbox Code Playgroud)
或者
df['col'].apply(str.lower)
df['col'].map(str.lower)
Run Code Online (Sandbox Code Playgroud)
好的,您已经有了按行排列的列表。然后:
df['col'].map(lambda x: list(map(str.lower, x)))
Run Code Online (Sandbox Code Playgroud)