NameError: name 'TabularList' is not definedImport. Error: cannot import name 'TabularList' from 'fastai.tabular.data' (D:\anaconda3\lib\site-packages\fastai\tabular\data.py)

from fastai import *
from fastai.tabular import *
from fastai.tabular.all import *
import pandas as pd

# set seed for reproducibility
custom_set_seed(42)

df = pd.read_csv('credit_card_default.csv', index_col=0, na_values='')
df.head()

DEP_VAR = 'default_payment_next_month'

num_features = list(df.select_dtypes('number').columns)
num_features.remove(DEP_VAR)
cat_features = list(df.select_dtypes('object').columns)

preprocessing = [FillMissing, Categorify, Normalize]

data = (TabularList.from_df(df, cat_names=cat_features, cont_names=num_features, procs=preprocessing).split_by_rand_pct(valid_pct=0.2, seed=42).label_from_df(cols=DEP_VAR).databunch())

I’m running the above code. I encountered a problem when running the last line. It said NameError: name 'TabularList' is not defined . I tried from fastai.tabular.data import TabularList but encountered another problem ImportError: cannot import name 'TabularList' from 'fastai.tabular.data' (D:\anaconda3\lib\site-packages\fastai\tabular\data.py) . Does anyone meet the same problem? Could anyone help me? thank you very much in advance!

2 Likes

I have the same problem.

Any reason that explain this error and how to solve it ?

If you’re getting this now it may be because you’re using fastai 2.0+, which does not have the TabularList API anymore, it’s now TabularPandas and a bit different of an API (though some things are similar enough)

Ok I’ll read the documentation and see how to use Tabular Pandas instead. thank you