Pandas dataframe upsert:在包含日期时间系列/列的数据帧上执行 dataframe.update 时出现 FutureWarning

mik*_*010 7 python numpy pandas

我正在尝试使用另一个数据帧中的数据更新一个数据帧。在大多数情况下这工作得很好。但是,当数据帧包含至少一列 datetime64 类型时,我会收到 FutureWarning。

这个简化的代码复制了这个问题:

    import pandas as pd
    index = pd.to_datetime(['01/03/2022', '01/04/2022'])
    data1 ={'value': pd.to_datetime(['01/05/2022', '01/06/2022'])}
    data2 ={'value': pd.to_datetime(['01/05/2022', '01/07/2022'])}

    df1 = pd.DataFrame(data=data1,  index=index)
    df2 = pd.DataFrame(data=data2,  index=index)
    df1.update(df2)
Run Code Online (Sandbox Code Playgroud)

和警告:

FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  df1.update(df2)
Run Code Online (Sandbox Code Playgroud)

这只发生在其中一个列/系列的类型为 datetime64 的数据帧中。在我的情况下,关于如何避免的警告中的建议似乎不是一个很好的解决方案,因为我可能有可变数量的列(通常我不会知道他们)。为此......一些问题:

  1. 有没有推荐的方法可以有效地解决这个问题。

  2. 或者我可以忽略这个警告吗?

  3. 如果这些警告很多,是否会导致代码性能问题