连接具有特定宽度整数的列

Uni*_*oln 3 python string dataframe pandas

我有一个带有两个整数列的数据框'df':

C1 C2
8  49
.. ..
Run Code Online (Sandbox Code Playgroud)

从这里,我想创建一个新列,用于连接具有特定宽度的两列.C1应为两位数宽,C2应为三位数宽,以便生成的列如下所示:

CODESUM 
08049
Run Code Online (Sandbox Code Playgroud)

前0对我来说不太重要.

到目前为止,我已尝试使用该str()功能str(df.C1),但没有成功.还有其他想法吗?

jez*_*ael 6

使用双str.zfill:

df['new'] = df.C1.astype(str).str.zfill(2) + df.astype(str).C2.str.zfill(3)
Run Code Online (Sandbox Code Playgroud)