Create new column with incremental values efficiently

前端 未结 4 1224
攒了一身酷
攒了一身酷 2021-02-07 03:23

I am creating a column with incremental values and then appending a string at the start of the column. When used on large data this is very slow. Please suggest a faster and eff

4条回答
  •  难免孤独
    2021-02-07 03:47

    One possible solution is with convert values to strings by map:

    df['New_Column'] = np.arange(len(df['a']))+1
    df['New_Column'] = 'str_' + df['New_Column'].map(str)
    

提交回复
热议问题