[英]how to reshape of pandas' data frame in following shape
pandas_data_frame['Data'] 包含格式为 (27,6,50,50,3) (samples,time_step,width,hight,channel) 的数据,但是当我塑造它时它给出 (27,) 并且当我看到形状时在它里面作为 pandas_data_frame['Data'][0] 它给出(6,50,50,3)。 那么如何将 pandas_data_frame 转换为具有形状(27、6、50、50、3)的 numpy.array?
首先,将 dataframe 转换为 NumPy 数组,然后再进行整形。
import pandas as pd
import numpy as np
data = {
"calories": [420, 380, 390,420, 380, 390,420, 380, 390],
"duration": [50, 40, 45,50, 40, 45,50, 40, 45]
}
#load data into a DataFrame object:
df = pd.DataFrame(data)
newarr = df.to_numpy()
print(newarr.shape)
newarr = newarr.reshape(6, 3)
print(newarr.shape)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.