[英]Adding Trailing Zeros to Decimal Places
I have a dataframe column where numerical data is stored (in thousands) with a '.'我有一个数据框列,其中以“.”存储数字数据(以千为单位)。 signifying a thousands separator.
表示千位分隔符。 The initial input file lacks trailing zeros, and a trailing decimal places are needed (to a maximum of 3).
初始输入文件缺少尾随零,需要尾随小数位(最多 3 位)。 Whole numbers should remain the same.
整数应该保持不变。
Please find a snippet of the dataframe df
below.请在下面找到数据框
df
的片段。
Input Data输入数据
Product Quantity
ABC 1
ZXC 2.1
QWE 3.21
ASD 4.123
Expected output预期输出
Product Quantity
ABC 1
ZXC 2.100
QWE 3.210
ASD 4.123
Any assistance that anyone could provide would be greatly appreciated.任何人都可以提供的任何帮助将不胜感激。
You can change float display format in a following way:您可以通过以下方式更改浮动显示格式:
pd.options.display.float_format = '{:,.3f}'.format
If you don't want integers to be formatted, use following:如果您不想格式化整数,请使用以下内容:
pd.options.display.float_format = lambda x: '{:,.0f}'.format(x) if float(x.is_integer()) else '{:,.3f}'.format(x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.