简体   繁体   English

Python 数据帧格式化字符串

[英]Python data frame formatting string

在此处输入图像描述

I've been working on filtering dataframe project.我一直在过滤 dataframe 项目。 I have a table on Excel, and I converted it to UTF-8 CSV file.我在 Excel 上有一个表,我将其转换为 UTF-8 CSV 文件。 I made all my columns on Excel as number with after comma-2 digit .我在 Excel 上将我的所有列都设为 comma-2 digit 之后的数字

However as you can see in figure some my columns are different.但是,正如您在图中看到的那样,我的一些列是不同的。 Default should be xx.xx but some columns seen as xx.xxxxx on dataframe.默认应为 xx.xx,但 dataframe 上的某些列被视为 xx.xxxxx。 In xx.xx columns I can filter properly, but the other columns are making problems.在 xx.xx 列中,我可以正确过滤,但其他列出现问题。 I tried to filter it like xx.xxxxx but it didn't work again.我试图像 xx.xxxxx 一样过滤它,但它不再起作用。 How can I get rid of this problem?我怎样才能摆脱这个问题?

In wiew data frame tool of pycharm I can format it but this works for only viewing.在 pycharm 的 wiew 数据框工具中,我可以对其进行格式化,但这仅适用于查看。 What should I do about this?我该怎么办?

You can use round to choose the given number of digits you want to keep.您可以使用round选择要保留的给定位数。 This way, you can have an equal number of decimals in all columns.这样,您可以在所有列中拥有相同数量的小数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM