0使用这种具有
map或
apply:
df = pd.Dataframe({'col1':[1.00, 1, 0.5, 1.50]})df['new'] = df['col1'].map('{0:g}'.format)#alternative solution#df['new'] = df['col1'].apply('{0:g}'.format)print (df) col1 new0 1.0 11 1.0 12 0.5 0.53 1.5 1.5print (df['new'].apply(type))0 <class 'str'>1 <class 'str'>2 <class 'str'>3 <class 'str'>Name: new, dtype: object
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)