Home  >  Q&A  >  body text

Rewrite the title as: How to convert data type of "unnamed 0" column of pandas dataframe from int64 to string or object

<p>I'm working on a small project trying to send a dataframe from pandas to a mysql database. </p> <p>My dataframe contains default unnamed columns and I want to send it to mysql server. My sql schema contains an id column of varchar(255) data type. </p> <pre class="brush:php;toolbar:false;">create table users_sample( id varchar(255) NOT NULL PRIMARY KEY, #other_columns)</pre> <p>When I try to send the code to the server, I get the following error</p> <blockquote> <p>sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1364, "Field 'id' has no default value")</p> </blockquote> <p>When I searched for a solution, it was suggested to change the data type from varchar to int and add auto_increment constraints. </p> <p>Please provide a solution. </p><p> Thanks in advance. </p>
P粉536532781P粉536532781381 days ago567

reply all(1)I'll reply

  • P粉063039990

    P粉0630399902023-09-05 18:05:31

    Maybe it can help you

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

    reply
    0
  • Cancelreply