在 pandas 中添加带有前缀的唯一标识符列

Adding unique identifier column with prefix in pandas

我正在尝试在 pandas DataFrame 中添加一个带有前缀“ACC”的唯一列。我该怎么做?

City               New column,      
Atlanta            ACC-1,
Newyork            ACC-2,

如果有唯一索引值使用:

df['New column'] = 'ACC-' + (df.index + 1).astype(str)

任何索引的另一个想法:

df['New column'] = np.arange(1, len(df) + 1)
df['New column'] = 'ACC-' + df['New column'].astype(str)

 df['New column'] = [f'ACC-{i+1}' for i in range(len(df))]