-1

I'm using pandas to get data from an URL and add it to a dataframe. It works but the df does have some NaNs in it which is causing me some problems. When I try to replace the NaNs with fillna(0) I get this error:

AttributeError: 'list' object has no attribute 'fillna'

Here is the code:

import pandas as pd

url = 'https://elderscrolls.fandom.com/wiki/Factions_(Skyrim)'
df = pd.read_html(url)
df = df.fillna(0)
skyrim_data = (df[0].to_dict(orient='records'))
halfer
  • 19,824
  • 17
  • 99
  • 186
robothead
  • 303
  • 2
  • 10

1 Answers1

3

read_html() does not returning a dataframe, it returns a list of dataframes instead because in one html there could be more than 1 tables. So if you just want the first table, you have to specify first which dataframe on the list you want to fillna(), then you can make it to dict.


import pandas as pd

url = 'https://elderscrolls.fandom.com/wiki/Factions_(Skyrim)'
df_list = pd.read_html(url)
df = df_list[0].fillna(0)
skyrim_data = (df.to_dict(orient='records'))

Yusuf Syam
  • 701
  • 1
  • 4
  • 18