![](/img/trans.png)
[英]I have a 3D numpy array. I want to flatten slices of it and then turn it back into the same 3D array. How can I do that?(python)
[英]I am trying to convert a row of data from a dataframe into a numpy array. How can I do this?
我有一个包含多列和多行的熊猫数据框。
下面只是我的数据框的一行,其中第一列是标题,第二列是数据。
我使用 full_df.iloc[0] 来提取第一行数据。
full_df 是我的熊猫数据框的名称。
year 2015.0
month 1.0
day 1.0
hour 0.0
minute 0.0
WDIR 13.0
WSPD 5.6
GST 6.9
WVHT 99.0
DPD 99.0
APD 99.0
MWD 999.0
PRES 1026.1
ATMP 11.4
WTMP 17.8
DEWP 999.0
VIS 99.0
TIDE 99.0
Name: 0, dtype: float64
如何将这些数据放入一个 numpy 数组中?
我尝试执行以下操作:
gfg = pd.Series(full_df.iloc[0])
gfg.to_numpy
但我收到以下错误:
AttributeError: 'Series' object has no attribute 'to_numpy'
你可以试试:
import numpy as np
gfg = pd.Series(full_df.iloc[0])
np.array(gfg)
这是你想要的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.