[Python] Python Pandas write to sql with NaN values

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to read a few hundred tables from ascii and then write them to mySQL. It seems easy to do with Pandas but I hit an error that doesn't make sense to me:

    I have a data frame of 8 columns. Here is the column list/index:

    metricDF.columns

    Index([u'FID', u'TYPE', u'CO', u'CITY', u'LINENO', u'SUBLINE', u'VALUE_010', u'VALUE2_015'], dtype=object)


    I then use to_sql to append the data up to mySQL

    metricDF.to_sql(con=con, name=seqFile, if_exists='append', flavor='mysql')


    I get a strange error about a column being "nan":

    OperationalError: (1054, "Unknown column 'nan' in 'field list'")


    As you can see all my columns have names. I realize mysql/sql support for writing appears in development so perhaps that's the reason? If so is there a work around? Any suggestions would be greatly appreciated.

    Continue reading...

Compartilhe esta Página