简体   繁体   中英

How to change the pandas dataframe 'unnamed 0' column datatype from int64 to string or object

I am working on small project where i am trying to send the pandas dataframe to mysql database.

My Dataframe contain default unnamed column which I want to send on mysql server. My sql schema contain id column with varchar(255) datatype.

create table users_sample(
    id varchar(255) NOT NULL PRIMARY KEY,
    #other_columns)

when i try to send the code on server i am getting the below errror

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1364, "Field 'id' doesn't have a default value")

When i serach for the solution it was suggesting that to change the datatype from varchar to int and put auto_increment constraint.

plz provide the solution.
Thanks in advance.

maybe help you

d1[['colname']] = d1[['colname']].astype(float)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM