简体   繁体   English

SFrames:将str转换为int或float

[英]SFrames: Converting str to int or float

I am starting to learn SFrames data structure lately. 我最近开始学习SFrames数据结构。 I wonder if anyone experienced the problem of converting a "str" column to "float" or "int" column. 我想知道是否有人遇到过将“ str”列转换为“ float”或“ int”列的问题。 In R, I could easily accomplish the task by as.numeric() or as.integer(). 在R中,我可以通过as.numeric()或as.integer()轻松完成任务。

How could I do that in SFrames (python)? 如何在SFrames(python)中做到这一点?

Thanks, 谢谢,

I've found this approach works. 我发现这种方法可行。

sf['column_name'] = sf['column_name'].astype(float)
sf['column_name'] = sf['column_name'].astype(str)

This doesn't work sometimes specially for empty columns. 有时这不适用于空列。 Its better to assign first to either string or float and then load elements. 最好先分配给字符串或浮点数,然后再加载元素。 Example

sf['column'] = ""  #for string
sf['column1'] = numpy.nan  #for float

and then load values. 然后加载值。 I got struck in similar situation. 我也遇到类似的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM