带有千空间分离器的格式大熊猫柱
我试图在任何地方看,但是我想要的东西没有确切的答案。
我知道一千的标准格式是一个逗号,但我希望有一个千分离器的空间。 我尝试了这个解决方案,但是仍然有一个逗号作为分离器:
d = {'col1': [1000, 20000], 'col2': [300000, 400000]}
df=pd.DataFrame(d)
df['col1']=df['col1'].map('{:,.0f}'.format)
df['col1'].astype(str)
df['col1'].replace(',',' ',inplace=True)
I tried to look everywhere, but there is no exact answer to what I'm looking for.
I know the standard formatting for a thousand is with a comma, but I want a space as a thousand separator.
I tried this solution, but there is still the comma as a separator:
d = {'col1': [1000, 20000], 'col2': [300000, 400000]}
df=pd.DataFrame(d)
df['col1']=df['col1'].map('{:,.0f}'.format)
df['col1'].astype(str)
df['col1'].replace(',',' ',inplace=True)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将完成的工作分配给变量,例如
df ['col1']。astype('str')
需要分配给df ['col1']
尝试此
输出
You need to assign the work done to the variable, for example
df['col1'].astype('str')
needs to be assigned todf['col1']
Try this
output