Durr
Durr

Reputation: 31

Looping over dataframes

So I have 4 dataframes that I am attempting to loop over.

I have created a list using the following code :

list = [df1,df2,df3,df4]

After that I would like to write them to an SQL Server using :

for i in list: i.to_sql(i,engine)

However this leads to the following error

'DataFrame' objects are mutable, thus they cannot be hashed

Any suggestions what I should be looking for?

Thanks in advance!

Upvotes: 0

Views: 67

Answers (2)

RasikhJ
RasikhJ

Reputation: 611

Use the itertuples method in pandas:

for i in dataframeList.itertuples():
    print i

Upvotes: 0

Rakesh
Rakesh

Reputation: 82765

You need to give the SQL table name in the first parameter

Ex:

l = [df1,df2,df3,df4]

for i in l:
    i.to_sql('TABLE_NAME',con=engine)

Upvotes: 1

Related Questions