I have a dataframe in which I have these column names
- 'team1',
- 'team2',
- 'city',
- 'date'.
What I want to do is to assign value of 'city' as 'dubai' when certain condition meets(which I am defining using mask).
This is what I am doing exactly:
matches[((matches['team1']=='mi') & (matches['team2']=='rcb') & (matches['date']=='2014-04-19')),'city']='Dubai'
When all the above condition meets I want to change value in 'city'(which is null now) to 'Dubai'
The problem which arises:
'Series' objects are mutable, thus they cannot be hashed
How can I do this?
Bracket (
[]
) notation accesses the__getitem__
method of a python object (if it has a method defined). For apd.DataFrame
object, you can pass an array like object via the bracketsdf[array_like_object]
and it will do one of a few thingspossibility 1
possibility 2
skipping other possibilities
You've got a
boolean_mask
And a
column
In this case, it's perfect for
loc
which can process exactly thatPer @JohnGalt