简体   繁体   中英

How to create json from a list of dataframes in a for loop?

I have a list with multiple dataframes in it. I want create json for each df in list using for loop.

I tried,

dfsize=[df df df]

for dfs in dfsize:
    dfs.to_json('areca{dfs}.json').format(dfs)

Was met with the error:

AttributeError: 'NoneType' object has no attribute 'format'

Is there a way to achieve this?

Also tried:

I tried

dfs.to_json('areca{dfs}.json'.format(dfs))

but got the error:

dfs.to_json('areca{dfs}.json'.format(dfs.index))

KeyError: 'dfs'

pandas.DataFrame.to_json returns None. This is causing the error. Format should be inside. Try this,

dfsize=[df df df]

for dfs in dfsize:
    dfs.to_json('areca{dfs}.json'.format(dfs))

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