I am using pandas (0.20.3)
and python 3.5.3
I have error like this
mysql.connector.errors.ProgrammingError: 1054 (42S22): Unknown column 'nan' in 'field list'
I thought it is because of mysql doesn't understand 'nan' as mull.
According to this article
The problem was fixed in pandas 0.15.0
However I still have this error. is there something wrong with my cord??
Or where should I fix??
stocksDf = pd.read_csv('companys.csv', names=['name','place'])
for i,row in stocksDf.iterrows():
sql = "insert into CompanyUs(name,place) VALUES(%s,%s)"
data = (row['name'],row['place'])
cur.execute(sql,data)
pprint("Company Write : %s" % row['name'])
conn.commit()
The article linked in the question is referring to DataFrame.to_sql() which you are not using in your code. If you want to maintain this way of writing to the database, you need to change the NaN
s in your DataFrame:
As explained in this question, the solution is, to change all NaN
-values to None
:
stocksDf = stocksDf.where((pd.notnull(stocksDf)), None)
Further important annotation from the original answer:
This changes the dtype of all columns to object
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With