简体   繁体   中英

how to add zero before a number if the number is less than 10 in a dataframe column

我在数据框中有一列,我想通过将cpro列中的每个值加到小于10的前面加上“ 0”,将其转换为两位数。我用以下方式将其转换为“ 0” '.join(df.loc [df ['cpro'] <10,'cpro']。astype(str).tolist())

其中x是要填充的字符串:

x.zfill(2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM