[英]I am trying to convert a row of data from a dataframe into a numpy array. How can I do this?
I have a pandas dataframe that contains multiple columns and rows.我有一个包含多列和多行的熊猫数据框。
Below is just one row of my dataframe, where the first columns are the headers and the second column is the data.下面只是我的数据框的一行,其中第一列是标题,第二列是数据。
I used full_df.iloc[0] to extract the first row of data.我使用 full_df.iloc[0] 来提取第一行数据。
full_df is the name of my pandas dataframe. 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
How can I get this data into a numpy array?如何将这些数据放入一个 numpy 数组中?
I tried doing the following:我尝试执行以下操作:
gfg = pd.Series(full_df.iloc[0])
gfg.to_numpy
But I get the following error:但我收到以下错误:
AttributeError: 'Series' object has no attribute 'to_numpy'
you can just try:你可以试试:
import numpy as np
gfg = pd.Series(full_df.iloc[0])
np.array(gfg)
Is it what you want?这是你想要的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.