Manish
Manish

Reputation: 170

ModuleNotFoundError: No module named 'fastai.structured'

I was trying to create some features from date column using 'add_datepart' function from 'fastai.structured' module in 'fastai' library. I got this error:

from fastai.structured import add_datepart 

After lot of googling, I found that 'structured' module was removed in 2018 update of fastai librabry. There are discussions around it but I could not find any solution for my problem. Is there any way to download old 'structured' module so that I can use add_datepart to create features from date column in my dataframe or is there any alternative solution to solve my problem? I have also tried to download old version of 'fastai' but installation of old version also failed:

!pip install fastai==0.7.0

Upvotes: 2

Views: 1484

Answers (1)

Manish
Manish

Reputation: 170

Finally I found the solution to this problem. 'structured' module in 'fastai' has been replaced with 'core' module inside 'tabular' folder in 'fastai' library. So instead of importing 'add_datepart' from 'structured' module import it from 'core'. In short we need to make following changes in our code:

Replace this code-

from fastai.structured import add_datepart

with following code-

from fastai.tabular.core import add_datepart

Rest all will remain unchanged. Tricky but a very simple solution. I hope this helps many other coders since I saw many coders struggling with this issue and asking for solution.

Upvotes: 4

Related Questions