【发布时间】:2020-07-17 15:41:02
【问题描述】:
| A | B
| a;b;c | 1;2;3
| a;b;c;d | 1
为了拆分列,我正在使用
new = df["A"].str.split(";", n=5, expand=True).
df['A1'] = new[0]
df['A2'] = new[1]
df['A3'] = new[2]
df['A4'] = new[3]
df.drop(columns=["A"], inplace=True)
df['B1'] = new[0]
df['B2'] = new[1]
df['B3'] = new[2]
df.drop(columns=["B"], inplace=True)
还有其他替代方法可以让我不需要计算每列中的数据数量吗? 我仍然需要输出类似于:
| A1| A2| A3| A4| B1| B2| B3
| a | b | c | | 1 | 2 | 3
| a | b | c | d | 1 | |
谢谢!
【问题讨论】: