簡體   English   中英

使用 Pandas 抑制整列行的科學計數法

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

嗨,我是 Python 的新手,但是經過大量視頻和請求后,我設法到達了某個地方。 我現在的問題是我在 CSV 中有一整列用科學記數法(浮點數)編寫,我正在嘗試在 XML 中顯示整列,但將整數顯示為字符串。

這是我的代碼:

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)

這就是我得到的:

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

所以我考慮使用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 

我只需要序列號。

嘗試

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

您可以在此處此處查看有關樣式的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM