Python Forum

Full Version: Updating df rows based on 2 conditions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
First post, so I apologize for any improper post etiquette, and am receptive to feedback. I have a data frame containing NBA games from the past several seasons(6000+ rows) and need to update some values to adjust for teams who have built new arenas. Data set looks like this

Output:
Date Visitor V_PTS Home H_PTS \ 0 2012-10-30 19:00:00 Washington Wizards 84 Cleveland Cavaliers 94 1 2012-11-02 19:30:00 Chicago Bulls 115 Cleveland Cavaliers 86 2 2012-11-17 19:30:00 Dallas Mavericks 103 Cleveland Cavaliers 95 Attendance Arena Location Capacity Yr Arena Opened \ 0 20562 Quicken Loans Arena Cleveland, Ohio 20562 1994 1 20562 Quicken Loans Arena Cleveland, Ohio 20562 1994 2 18633 Quicken Loans Arena Cleveland, Ohio 20562 1994 Season 0 2012-13 1 2012-13 2 2012-13
Here is what I have so far for a function I am trying to apply with no success. Any help would be appreciated on what I am doing wrong or if there is a better way to do this and also how to apply the function properly to the df which I named NBA.

def old_arena(home):
    for team in home :
        if (team == ('Detroit Pistons') & (nba['Date']<'2016-9-30')):
            nba['Arena'] = 'The Palace of Auburn Hills'
            nba['Location'] = 'Auburn Hills, Michigan'
            nba['Capacity'] = 22076
            nba['Yr Arena Opened'] = 1988
        elif ((team == 'Sacremento Kings') & (nba['Date']<'2017-9-5')):
            nba['Arena'] = 'Sleep Train Arena'
            nba['Capacity'] = 17317
            nba['Yr Arena Opened'] = 1988
You are abusing pandas - here's an example of selecting rows by condition - assuming that your column Date is of
dtype=datetime64
games[(games['Date'] < pd.Timestamp('2016-9-30')) & (games['Visitor'] == 'Chicago Bulls')]
You cannot change cells in a row like that - but that (at the moment) is beyond my knowledge

PS Googled
Quote:update selected dataframe row
, got this answer, elementary Watson