如何将最后一列拆分成多列,但在python

时间:2017-06-12 07:31:14

标签: python pandas split

虽然拆分列很容易,但是如何保留拆分列?

E.g。

a;b;c;d;e;f;g
a;b;c;d;e;f;g
a;b;c;d;e;f;g
a;b;c;d;e;f;g

现在将g分为h,i,j,k,但保持g为g(g - > h,i,j,k)

a;b;c;d;e;f;g;h;i;j;k
a;b;c;d;e;f;g;h;i;j;k
a;b;c;d;e;f;g;h;i;j;k
a;b;c;d;e;f;g;h;i;j;k

1 个答案:

答案 0 :(得分:0)

您似乎需要split

df[['h','i','j','k']] = df['g'].str.split(',', expand=True)

或者:

df1 = df['g'].str.split(',', expand=True)
df1.columns = ['h','i','j','k'] 
df = pd.concat([df, df1], axis=1)