python - Write Pandas DataFrame in to MySQL database -
i'm trying write pandas dataframe mysql database following code.
import pandas pd import numpy np pandas.io import sql import mysqldb  df = pd.dataframe([[1.1, 1.1, 1.1, 2.6, 2.5, 3.4,2.6,2.6,3.4,3.4,2.6,1.1,1.1,3.3], list('aaabbbbabcbddd'), [1.1, 1.7, 2.5, 2.6, 3.3, 3.8,4.0,4.2,4.3,4.5,4.6,4.7,4.7,4.8]]).t  db = mysqldb.connect("192.168.56.101","nilani","123","test") cursor = db.cursor()  cursor.execute("drop table if exists test")  sql = """create table test (          id  int not null,          col1 char(20),          col2 char(20),            col3 char(20))"""  cursor.execute(sql)  sql.write_frame(df, con=db, name='test', flavor='mysql')  db.close()   i have been referring this question , other resources. way following error. reason?
sql.write_frame(df, con=db, name='test', flavor='mysql') attributeerror: 'str' object has no attribute 'write_frame'      
you have overwritten from pandas.io import sql sql = """..., sql string , no longer pandas module holds write_frame function.
edit: attributeerror: 'numpy.int64' object has no attribute 'replace' error due fact use integer column labels (this bug). try setting columns labels else, eg:
df.columns = ['col1', 'col2', 'col3']      
Python - Write Pandas Dataframe In To Mysql Database - >>>>> Download Now
ReplyDelete>>>>> Download Full
Python - Write Pandas Dataframe In To Mysql Database - >>>>> Download LINK
>>>>> Download Now
Python - Write Pandas Dataframe In To Mysql Database - >>>>> Download Full
>>>>> Download LINK cL