簡體   English   中英

AttributeError:Float' object 沒有屬性日志 /TypeError: 輸入類型不支持 ufunc 'log'

[英]AttributeError:Float' object has no attribute log /TypeError: ufunc 'log' not supported for the input types

我在一列('2.4M')中有一系列熒光強度數據。 我嘗試通過獲取列'2.4M'的ln來創建一個新列'ln_2.4M',但出現錯誤:

AttributeError: 'float' object 沒有屬性 'log'

df["ln_2.4M"] = np.log(df["2.4M"])

我嘗試使用 for 循環在“2.4M”列中的每個熒光數據上迭代日志:

ln2_4M = []
for x in df["2.4M"]:
    ln2_4M = np.log(x)
    print(ln2_4M)

盡管它正確打印出 ln2_4M 作為“2.4M”列的日志,但我無法使用這些數據,因為它同時給出了 TypeError: ufunc 'log' not supported for the input types,並且無法安全地將輸入強制轉換為任何根據轉換規則“安全”支持的類型

不知道為什么? - 任何有助於了解正在發生的事情以及如何解決此問題的幫助表示贊賞。 謝謝

.
然后我嘗試使用下面的方法並且它有效:

df["2.4M"] = pd.to_numeric(df["2.4M"],errors = 'coerce')

df["ln_24M"] = np.log(df["2.4M"])

暫無
暫無

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

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