【问题标题】:extract substring and covert into float in a new column提取子字符串并在新列中转换为浮点数
【发布时间】:2021-03-21 15:02:55
【问题描述】:

这是我的桌子

我只想获取年龄数字并将其放入新列中。我知道我们会使用 for 循环,但是如何使用。

期望的输出 在 dob_num 列中,我希望下一行有 33 和 30

【问题讨论】:

    标签: python python-3.x string for-loop


    【解决方案1】:

    如果年龄的格式每次都一样,可以使用下面的代码。否则可以使用正则表达式

        df['dob_num'] = [float(i[-3:-1]) for i in df.dob]
    

    【讨论】:

    • 很高兴我能帮上忙。
    猜你喜欢
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 2022-11-08
    • 2017-09-26
    • 1970-01-01
    相关资源
    最近更新 更多