在 pandas 中将字符串转换为小写 [英] Converting strings to a lower case in pandas

查看:94
本文介绍了在 pandas 中将字符串转换为小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含域名的数据:

I have a data that contains domain names:

 url          var1
www.CNN.com   xsd
www.Nbc.com   wer
www.BBc.com   xyz
www.fOX.com   zyx
....

数据属于系列类型.我正在使用以下内容将 url 变量转换为小写:

The data is of the Series type. I am using the following to convert url variable to lower case:

df.apply(lambda x: x.astype(str).str.lower())

但是,它们保持不变.

我做错了什么?

推荐答案

df['url'] = df['url'].str.lower()

应该对系列进行操作并将其替换为小写版本.

should operate on the series and replace it with the lower case version.

这篇关于在 pandas 中将字符串转换为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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