我的熊猫数据帧具有NAN值。。我正在使用"df.dropna"方法从数据帧中删除所有丢失的值,以便将其写回Oracle数据库表。但在DB表中,Nan值被替换为0,我希望它们保持为Null。或者,是否有任何方法可以使用包含缺失/NaN值的数据帧来更新Oracle表。NaN在数据库中应变为Null。请帮忙,因为我是蟒蛇和熊猫的新手。
我正在使用
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