13 Feb 2024

Posted on:

06 Feb 2024

0

# Resolved:Exercise question: price, size, year, view

Hello,

While the conversion of view data into numerical 0 and 1 was quite easy, I am unable to convert the year data from 2006 to 2018 into other numbers.

I tried using 'map' as well as np.where to convert a particular year (say 2018) into 1.

Just to add, the operation runs successfully without any error when using map or np.where but the output is NaN in case of map and the last argument i.e. 0

data['year'] = np.where(data['year'] == 2018, 1, 0)

Regards,

Jigar

Instructor
Posted on:

08 Feb 2024

0

Hey Jigar,

Thank you for reaching out!

Could you please specify the course exercise this example is taken from? This will help me execute the code and assist you effectively.

Kind regards,

365 Hristina

Posted on:

08 Feb 2024

0

Hello Hristina,

I realised this question did not get mapped to that particular video.

It is taken from Machine Learning in Python>> Linear Regression>> Dealing with categorical data.

The data set has price, size, year and view as the columns. The official answer suggests only to convert the 'view'(categorical) into 1 and 0 (numerical).

I am just trying to experiment converting 'year' into 1 and 0 as well with recent years 2015-2018 (recent) as 1s and 2006 to 2014 (old) as 0.

I even tried after deleting the view column altogether.

Just to add, the operation runs successfully without any error when using map or np.where but the output is NaN in case of map and the last argument i.e. 0

data['year'] = np.where(data['year'] == 2018, 1, 0)

Regards,

Jigar

Instructor
Posted on:

12 Feb 2024

1

Hey again, Jigar, and apologies for the delayed response.

To map 2015-2018 to 1 and 2006-2014 to 0, the following line of code should work (just as you've suggested):

``data['year'] = np.where(data['year'] >= 2015, 1, 0)``

Let me know if you run into additional issues.

Kind regards,

365 Hristina

Posted on:

13 Feb 2024

0

Hello Hristina,

Like always, you are a terrific help.

The code works perfectly fine.

Thank you.

Regards,

Jigar

Instructor
Posted on:

13 Feb 2024

0

Thank you, happy to help! Enjoy the rest of the course!

Kind regards,

365 Hristina