简体   繁体   English

我正在尝试将数据帧中的一行数据转换为一个 numpy 数组。 我怎样才能做到这一点?

[英]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.

相关问题 我有一个 3D numpy 阵列。 我想将其切片,然后将其转回相同的 3D 阵列。 我该怎么做?(python) - 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) 从数组转换为pandas.dataframe时如何在数据框中仅添加一行 - How can i add just one row in dataframe when I convert from array to pandas.dataframe 如何将文件从 pandas dataframe read_csv 转换为 numpy 数组,其中逗号和“numpy.ndarray”类型之间? - How do I convert a file from a pandas dataframe read_csv into a numpy array with commas in between and 'numpy.ndarray' type? 如何从数组更改属性访问json数据。 JS jQuery - How do I access json data with changing property from the array. JS-Jquery 从数组中删除值。 我该如何运作 - Removing a value from an array. How can I get it to work 将 256x256x256 numpy 阵列调整为 64x64x64 numpy 阵列。 我正在尝试实现 4 的 window 大小来平均元素 - Resize 256x256x256 numpy array into 64x64x64 numpy array. I am trying to implement a window size of 4 to average the elements 我正在尝试从二维数组中找到对角线的总和。 但是获取它的地址而不是它的价值。有人可以向我解释一下吗? - I am trying to find sum of diagonal from 2d array. But getting its address instead of its value .Can anyone explain this to me? Scala - 如何从 DataFrame 转换为 Array[caseclass] - Scala - how do I convert from DataFrame to Array[caseclass] 如何有效地将4D numpy数组转换为以索引为列的pandas DataFrame? - How can I efficiently convert a 4D numpy array into a pandas DataFrame with indices as columns? 如何使用二维数组检查“连续 4 个”? 请注意,我没有使用“numpy”,因为我对编码非常陌生 - How do I check for a "4 in a row" with a 2d array? Note that I'm not using "numpy" as I am extremely new to coding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM