[英]How do I get rid of TypeError: strptime() argument 1 must be str, not float in read_csv?
[英]How do I get rid of unnecessary dot symbol for float ending with 0
例如,我在 Python 中有一個數組,看起來像這樣
x = np.array([0, 1, 1.5, 2])
但是當我執行print(x)
時,它會顯示這個
x = [0. 1. 1.5 2. ]
我該怎么做才能打印x = [0 1 1.5 2]
而不帶“。” 沒有任何其他小數的數字的符號?
由於您有一個 NumPy 浮點數組,因此您在打印時會得到這些點。 要只打印不帶點的數字,如果它們可以表示為 integer,則必須將列表中的數字轉換為整數。
print([int(y) if y.is_integer() else y for y in x])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.