Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更换';楠';在使用psycopg2将数据从python上载到postgresql时使用blank_Python_Postgresql - Fatal编程技术网

更换';楠';在使用psycopg2将数据从python上载到postgresql时使用blank

更换';楠';在使用psycopg2将数据从python上载到postgresql时使用blank,python,postgresql,Python,Postgresql,我有一个数据帧,其中有一些空值。除ID和date列外,所有列都是字符串 ID product_num order_date desc employeID 1 100234 2020-02-03 abcx 101 2 102 问题是当我尝试将上面的数据文件上传到PostgreSQL(V 11)时,空白单元格被转换为字符串 n。因此,在DB中,我看

我有一个数据帧,其中有一些空值。除ID和date列外,所有列都是
字符串

ID    product_num    order_date   desc      employeID
1     100234         2020-02-03   abcx       101
2                                            102

问题是当我尝试将上面的数据文件上传到PostgreSQL(V 11)时,空白单元格被转换为字符串<代码> n<代码>。因此,在DB中,我看到以下内容

 ID    product_num    order_date   desc      employeID
  1     100234         2020-02-03   abcx       101
  2        nan          nan          nan       102
显然,这不是预期的。相反,我希望在DB中将它们也视为空白(或NULL)

如何解决这个问题?我正在根据以下函数将df中的所有列转换为与psycopg2等效的数据类型:

def sqlcol(df):    
  dtypedict = {}
  for i,j in zip(dfcolumns, dfdtypes):
    if "object" in str(j):
        dtypedict.update({i: sqlalchemy.types.String()})
    if "datetime" in str(j):
        dtypedict.update({i: sqlalchemy.types.DateTime()})
    if "float" in str(j):
        dtypedict.update({i: sqlalchemy.types.String()})
    if "int" in str(j):
        dtypedict.update({i: sqlalchemy.types.String()})
  return dtypedict
但我没有得到任何结果。
因此,任何帮助都将不胜感激。

您如何将数据帧上载到Postgres(确切的命令)?当你说列(ID和日期除外)是字符串时,你是在说Postgres列吗?数据帧中的空格实际上是
NULL
还是空字符串?我正在使用df.to_sql()并在那里使用上述
sqlcol(df)
函数来更改数据类型。在数据帧中,它是以
nan
的形式出现的,它们实际上是空的。