I have the following sample data:
| | date | value |
|:---- |:------:| -----:|
| 0 | 2021/05| 50 |
| 1 | 2021/06| 60 |
| 2 | 2021/07| 70 |
| 3 | 2021/08| 80 |
| 4 | 2021/09| 90 |
| 5 | 2021/10| 100 |
I want to update the data in the 'date' column, where for example '2021/05' becomes '05/10/2021', '2021/06' becomes '06/12/2021' and so long (I have to choose the new date manually for every row).
Is there a better/more clever way to do it instead of:
for i in df.index:
if df['date'][i] == '2021/05':
df['date'][i] = '05/10/2021'
elif df['date'][i] == '2021/06':
df['date'][i] = '06/12/2021'
The problem is that there are more than hundred rows that have to be updated and the code above will be tremendously long.
Aucun commentaire:
Enregistrer un commentaire