I have a numpy.DataFrame say df with 3 columns, col_1, col_2, col_3. Data in col_1 are numpy.ndarray and looks like this: array([ 0.216, -0.290, 0.349])
How could I use np.hstack() to expand the DataFrame with columns consist of each data point in col_1?
i.e. Original DataFrame
col_1 col_2 col_3
------------------------------------------------------
0 [0.216, -0.290, 0.349] NORMAL N09_M07_F10_K001_1
Supposed DataFrame
col_3 col_2 0 1 2
------------------------------------------------
0 N09_M07_F10_K001_1 NORMAL 0.216 -0.290 0.349
I'd tried like this:
Supposed_DataFrame = pd.concat(
[df[['label', 'filename']],
pd.DataFrame(np.hstack(df["signal"].values).T)
],
axis=1)
but the output was:
col_3 col_2 0
-----------------------------------
0 N09_M07_F10_K001_1 NORMAL 0.216
any simpler solutions will be appreciated 😊