如何仅在Python Pandas中使用3个字符的Pandas DataFrame选择行?
我有下面的pandas dataframe,col1是字符串数据类型:
col1
-----
"123"
"1111"
"287777"
NaN
"222"
我只需要选择这些行,其中“ col1”中的字符串具有3个字符,因此我需要以下类似的东西:
col1:
-----
"123"
"222"
我该如何在python pandas中做到这一点?
I have Pandas DataFrame like below, col1 is STRING data type:
col1
-----
"123"
"1111"
"287777"
NaN
"222"
And I need to select only these rows where string in "col1" has 3 characters, so as a result i need something like below:
col1:
-----
"123"
"222"
How can I do that in Python Pandas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此任务的功能:
输出:
You can use the pandas.Series.str.len function for this task:
Output: