【问题标题】:Change column names' dtype from float to string?将列名的 dtype 从浮点数更改为字符串?
【发布时间】:2020-06-25 15:40:17
【问题描述】:

我最近在尝试将数据转换为 tensorflow 格式时遇到此错误:

Error in py_call_impl(callable, dots$args, dots$keywords) : 
ValueError: column_name: age vocabulary dtype must be string or integer. dtype: <dtype: 'float64'>. 

是否有命令可以让我将数据框列名的格式从浮点数更改为字符串?

谢谢!

【问题讨论】:

    标签: r string columnname dtype


    【解决方案1】:

    NLP(自然语言处理)包中,您可以使用as.String(x) 将列名强制转换为字符串,然后将它们再次存储为数据框的列名。这可以迭代地完成:

    library(NLP)
    
    float_colnames <- colnames(df)
    
    string_colnames <- rep("", length(float_colnames))
    for (i in 1:length(float_colnames)) {
      string_colnames[i] <- as.String(test[i])
    }
    
    colnames(df) <- string_colnames
    

    希望这会有所帮助!

    【讨论】:

    • 谢谢! @Kel Varnsen
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 2018-01-11
    • 2016-03-31
    • 1970-01-01
    • 2020-02-08
    相关资源
    最近更新 更多