I have a dataframe of people and rather than editing it in excel I would like to be able to enter data in pandas directly.
In the example table below, John has nothin in df['Group']
DF
| Name | ID | Grade | Group | |
|---|---|---|---|---|
| 0 | John | 001 | 89 | Nan |
| 1 | Jane | 002 | 56 | Group 1 |
| 2 | Joan | 003 | 91 | Group 2 |
| 3 | David | 004 | 45 | Group 1 |
I'd like to be able to change this to 'Group 4', preferably without using iloc (it's a big-ish df).
| Name | ID | Grade | Group | |
|---|---|---|---|---|
| 0 | John | 001 | 89 | Group 4 |
| 1 | Jane | 002 | 56 | Group 1 |
| 2 | Joan | 003 | 91 | Group 2 |
| 3 | David | 004 | 45 | Group 1 |
I have tried
df.loc[df['Name'] == 'John']['Group'] = 'Group 4'
df2.loc[0,'Group'] = 'Group 4'
These don't work (probably obvious to you).
Is there a way to do this?