'dataframe dtypes to create table sql stat
I need to insert into a CREATE TABLE stat the names of the columns and the types, with the comma at the end of each line.
What I get with df.dtypes
is:
Name object
Age int64
City object
Marks float64
dtype: object
what I need is:
Name object,
Age int64,
City object,
Marks float64
in order to create a query like this:
cursor.execute("""
CREATE TABLE tab1 (
Name object,
Age int64,
City object,
Marks float64
)
""")
I tried with converting it to a dictionary or to a list, but still no results.
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|