Assigning values in DataFrame

bool_os = laptops["os"]=="No OS"
laptops[bool_os]["os_version"] = "Version Unknown" #method 1
laptops.loc[bool_os, "os_version"] = "Version Unknown" #method 2

I’ve tried to assign values using those two methods.
Why doesn’t the first one work as both references gives the same series?

Hello @MichaLewsza,

Welcome to the community! I believe both methods should give you the same series.

What do you mean by the first one doesn’t work?
You can also include a link to the course page.

Hello @doyinsolamiolaoye,

What I mean is that the first method leaves the dataframe without any changes.
Only second method assigns string: “Version Unkown” to the specified places in dataframe.

Here’s the link to the course page:

Thanks for your reply!

This will help

1. Returning a view versus a copy

2. Why does assignment fail when using chained indexing?


@DishinGoyani thank you a lot!