![](/img/trans.png)
[英]How to convert pandas.core.series.Series type to 2D array?
[英]How to convert pandas series to 2D array?
由于我的编辑已从@RikKraan 帖子中删除,因此这里是我在对他的回复的评论中提到的答案。
首先将reset_index
应用于您的系列,然后使用to_numpy
,即
series.reset_index().to_numpy()
请注意, reset_index
将系列转换为数据帧。
如评论中所述,OP 希望将 IP 存储为浮点数。 这可以通过删除.
在 IP 字符串中,并在转换之前将索引转换为float
,如上所述。 IE
series.index = series.index.str.replace('.','').astype(float)
series.reset_index().to_numpy()
这将为您提供具有 dtype float 的 2D numpy 数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.