设置不兼容的数据类型的项目已被弃用,并将在未来的pandas错误中引发。

3
我有以下代码,例如在目前的情况下可以正常工作,但在未来可能无法正常工作。
    total.name = 'New_Row'
    total_df = total.to_frame().T
    total_df.at['New_Row', 'CURRENCY'] = ''
    total_df.at['New_Row', 'MANDATE'] = Portfolio
    total_df.at['New_Row', 'COMPOSITE'] = 'GRAND TOTAL'
    total_df.set_index('COMPOSITE',inplace=True)

由于发生错误。
FutureWarning: Setting an item of incompatible dtype is deprecated and 
will raise in a future error of pandas. Value 'GRAND TOTAL' has dtype incompatible with float64, please explicitly cast to a compatible dtype first.
  total_df.at['New_Row', 'COMPOSITE'] = 'GRAND TOTAL'

如何修复这个问题?
变量 total 是:
CURRENCY
MANDATE             Mandate_Test
USD AMOUNT          123
LOCAL AMOUNT        12
Beg. Mkt            123
End. Mkt            456
Name: New_Row, dtype: object

请确保['New_Row', 'COMPOSITE']的输入是float64类型。'GRAND TOTAL'是一个字符串,所以不适用。 - undefined
你为什么说第二个答案是由人工智能生成的? - undefined
@OCa 因为在上 Stack Overflow 之前,我在聊天 GPT 上询问了一下,看它能否帮忙。结果它给出了同样错误的答案。 - undefined
1个回答

3

2
我认为你是对的,但是在我确信没有其他解释的情况下,我会接受。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接