简体   繁体   English

使用 Pandas 抑制整列行的科学计数法

[英]Suppress scientific notation for a whole column line with Pandas

Hi I am quite new in Python, but after a lot of videos and requests i´ve managed to get somewhere.嗨,我是 Python 的新手,但是经过大量视频和请求后,我设法到达了某个地方。 My problem now is that I have a whole column in a CSV written in scientific notation (float) and what I am trying is to display the whole column in an XML but showing the whole number as a string.我现在的问题是我在 CSV 中有一整列用科学记数法(浮点数)编写,我正在尝试在 XML 中显示整列,但将整数显示为字符串。

Here´s my code:这是我的代码:

pd.options.display.float_format = '{:.0f}'.format
data = pd.read_csv(report, delimiter=',') 
commissioned = data.loc[data['SerialNumberState'] == 'Commissioned'] 
commissioned.to_csv('C:/Users/Engineering/Desktop/Commisioned.csv', index=False) 
commissioned.reset_index(drop=True, inplace=True) 
com_sn = commissioned['SerialNumber']
com_sscc = commissioned['ParentSerialNumber'] 
sscc = com_sscc.drop_duplicates() 
print(sscc)

And this is what i get:这就是我得到的:

TypeError: write() argument must be str, not Series

So i thought about using print(str(sscc)) function but it prints a lot of stuff that i don´t need (as the index and data information), as shown below:所以我考虑使用print(str(sscc)) function 但它打印了很多我不需要的东西(作为索引和数据信息),如下所示:

0    257138440200000160
1    257138440200000288
2    257138440200000224
3    257138440200000256
4    257138440200000192
12                  nan
15   257138440200000096
21   257138440200000032
22   257138440200000064
Name: ParentSerialNumber, dtype: float64 

I only need the SerialNumbers.我只需要序列号。

Try尝试

import pandas as pd
pd.options.display.float_format = '{:,.2f}'.format

You can see more about styling here and here您可以在此处此处查看有关样式的更多信息

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

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