-2

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'

Illuminate
  • 109
  • 2
  • 10
  • `dfsize=[df df df]` should be `dfsize=[df, df, df]` right, change the line to `dfs.to_json('areca{}.json'.format(name_of_dfs))`, the `format` function is for string, so it right after your string, not after the `to_json` function, – Phung Duy Phong Feb 21 '20 at 06:44
  • example: `'areca{}.json'.format('test')` -> `arecatest.json`, so you probably need a way to determine the name of df – Phung Duy Phong Feb 21 '20 at 06:45
  • Seem like you miss a character ')' in the end. – CuCaRot Feb 21 '20 at 06:51

1 Answers1

-1

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))
soumith
  • 536
  • 1
  • 3
  • 12