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