【问题标题】:How do I detect if a string with whitespace contains a number in pandas?How do I detect if a string with whitespace contains a number in pandas?
【发布时间】:2022-12-01 14:01:24
【问题描述】:

I'm trying to seperate a list of mailing addresses and names that are intertwined in a single column due to poor formating. I initially wanted to grab all of the entries that are alphanumeric so I can separate them however I'm having trouble with the .isalnum() function. My string is a mailing address so I can't remove all of the white space as it would ruin the formatting.

'123 main st'.isalnum()

doesn't work because of the white space and I can't quite figure out how to effectively check if this is correct.

【问题讨论】:

  • What's your data frame and expected output?
  • '123 main st'.replace(' ', '').isalnum() or using a regex.

标签: python pandas


【解决方案1】:

Possible duplicate: Check if a string contains a number.

def has_numbers(inputString):
    return any(char.isdigit() for char in inputString)

has_numbers("123 main st")
True

【讨论】:

    猜你喜欢
    • 2022-12-01
    • 2022-08-17
    • 2022-12-27
    • 2021-11-18
    • 2022-01-04
    • 2022-12-02
    • 2022-12-02
    • 2022-12-28
    • 2022-11-20
    相关资源
    最近更新 更多