【问题标题】:How to update a pandas dataframe with Nans inside an Oracle table so that the Nans become NULLs?如何使用 Oracle 表中的 Nans 更新 Pandas 数据框,以使 Nans 变为 NULL?
【发布时间】:2019-11-08 04:10:18
【问题描述】:

我的 pandas 数据框有 NAN 值。我正在使用“df.dropna”方法从我的数据框中删除所有缺失的值,以便我可以将其写回我的 Oracle 数据库表。 但是在 DB 表中,Nan 值被替换为 0,我希望它们保持为 Null。 或者,有没有办法用包含缺失/NaN 值的数据框更新 Oracle 表。 NaN 应该在数据库中变为 Null。 请帮忙,因为我是 python 和 pandas 的新手。

【问题讨论】:

  • df_new = df.where((pd.notnull(df)), None)

标签: python sql pandas oracle


【解决方案1】:

我正在为此使用:

df_new = df.where((pd.notnull(df)), None)

例子:

import pandas as pd
import numpy as np
df = pd.DataFrame(['str1', np.nan])
df


0   str1
1   NaN


df_new = df.where((pd.notnull(df)), None)
df_new

0   str1
1   None

【讨论】:

    猜你喜欢
    • 2023-02-24
    • 2022-08-17
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 2019-02-26
    • 2018-01-26
    相关资源
    最近更新 更多