I am using pandas 0.16 and sqlalchemy. Is it possible to export just the structure, i.e. column names and data types but no rows, of a dataframe to SQL?
The closest I managed to get to was to export the first row only:
df.ix[[0],:].to_sql( tablename, myconnection )
And then I'd have to do a truncate table. However, there are inconsistencies between the to_csv and the to_sql methods: to_csv writes boolean fields as the strings 'TRUE' or 'FALSE' , whereas to_sql writes them as 0 or 1. This means that importing files creates with dataframe.to_csv is more complicated than it should be.
If I run
df.ix[[],:].to_sql( tablename, myconnection )
that doesn't work because all columns are exported as text.