【问题标题】:Alternative to deprecated pd.Series().convert_objects(convert_numeric = true), able to parse string替代已弃用的 pd.Series().convert_objects(convert_numeric = true),能够解析字符串
【发布时间】:2017-05-25 13:39:20
【问题描述】:

我想知道对于以下情况是否存在pandas.Series(x).convert_objects(convert_numeric = true) 的替代方案:

px = dt.ix[:,1] # pandas.core.series.Series
pmat = pd.Series(px).convert_objects(convert_numeric = True) # works but convert_objects is deprecated in future version

如果有关数据的更多信息可能会有所帮助,请注意:

dt:Type = DataFrame, size=(1790,2), Value= column names: 0,1
px: Type=Series, size=(1790,), Value= class 'pandas.core.series.Series'

到目前为止,我已经尝试过以下一些搜索:

pmat = px.apply(pd.to_numeric, errors="ignore")
pmat = pd.to_numeric(px) # Unable to parse string

最好的,

【问题讨论】:

    标签: python-3.x pandas numpy series


    【解决方案1】:

    我认为您需要与Series 一起使用的to_numericdf 的列):

    #invalid parsing will be set as NaN
    pmat = pd.to_numeric(px, errors='coerce')
    

    或者:

    #invalid parsing will return the input
    pmat = pd.to_numeric(px, errors='ignore')
    

    还有ixdeprecated,最好用iloc

    【讨论】:

    • 非常感谢您在这方面的及时性。最佳
    猜你喜欢
    • 2016-01-12
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 2014-02-18
    相关资源
    最近更新 更多