Guided Project: Popular Data Science Questions - Converting NaN's into Zer0s

Screen Link:
Popular Data Science Questions | Dataquest

Hi beautiful people :),

Trying to progess on this project, but got stuck in trying to convert the missing values into 0. I’m using this piece of code, after importing of course the numpy, but it results in the same Dataframe with the same NaN datapoints…hhhmmmm, donnu what to do nor whats the problem because its not returning any error:

My Code:

posts.loc[posts['FavoriteCount'] == np.nan, 'FavoriteCount'] = 0

Any help?

Thanks!

Hi Abel,

Try using fillna(0) on the column of interest and then re-assign the result to that column.

1 Like

Yes, it worked, Elena :slight_smile:

posts['FavoriteCount'] = posts['FavoriteCount'].fillna(0)

Thank you for your help!

But just out of curiosity, why my piece of code was not doing the job?

1 Like

Hi Abel,

Cool! I’m glad that it was helpful :blush:
As for your piece of code, in this StackOverflow post there is a great answer to your question. So, when working with missing values, we should always use special functions: fillna(), isnull(), notnull(), etc.

1 Like

Thanks for sharing that interesting post, Elena :slight_smile:

As a token of my appreciation, I’ll share with you my last DQ Project:
Popular Data Science Questions.ipynb (155.9 KB) Popular Data Science Questions.py (15.7 KB)
:wink:

Obrigado, once again :slight_smile:

Click here to view the jupyter notebook file in a new tab

Hi Abel,

Your project looks amazing, thanks for sharing it! :star2: I love your visualizations, they are really cool, clean and informative, without any cluttering, just the best way to communicate the results. I’m very glad that I somehow contributed with my help in such a great project! :star_struck:

Hello everyone, Here is the .ipynb completed project on popular data science questions. I took help from the dataquest community in completing this project. Thank you for all your support. Your valuable feedback on this is appreciated.
Guided Project - Popular Data Science Questions.ipynb (381.3 KB)
.

Click here to view the jupyter notebook file in a new tab

1 Like

Hi @ashwin86rajan,

Welcome to the Community and congratulations on sharing your first project with us!

Could you please post it here? It will be easy for the students who did the same project to find your work. Thank you, looking forward to seeing your project there! :slightly_smiling_face:

Sure. Did not see that first.

1 Like