[英]How can I split this dataframe in columns
I have a Pandas dataframe with N columns, each column containing a list of 3 values ( x
, y
and z
):我有一个带有 N 列的 Pandas dataframe,每列包含 3 个值(
x
、 y
和z
)的列表:
I want to get a new dataframe containing 3N columns, each one containing each of the coordinate values for each column (for example, IndexDistalJoint_x
, IndexDistalJoint_y
and IndexDistalJoint_z
, and so on with the remaining original columns).我想得到一个新的 dataframe 包含 3N 列,每一列都包含每一列的每个坐标值(例如,
IndexDistalJoint_x
、 IndexDistalJoint_y
和IndexDistalJoint_z
,以及剩余的原始列等等)。
Any idea?任何的想法? Thanks in advance.
提前致谢。
Consider this DataFrame:考虑这个 DataFrame:
A B C
0 [1, 2, 3] [4, 5, 6] [7, 8, 9]
1 [10, 11, 12] [13, 14, 15] [16, 17, 18]
Then:然后:
data = []
for c in df.columns:
x = df[c].apply(pd.Series)
x.columns = [f"{c}_{ch}" for ch in "xyz"]
data.append(x)
print(pd.concat(data, axis=1))
Prints:印刷:
A_x A_y A_z B_x B_y B_z C_x C_y C_z
0 1 2 3 4 5 6 7 8 9
1 10 11 12 13 14 15 16 17 18
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.