Select by date to change value

+1 vote

df_subset looks like this:

          day        holiday       date    traffic_volume
0     Tuesday  New Years Day 2013-01-01              1439
1     Tuesday           None 2013-01-01              1502
2     Tuesday           None 2013-01-01               933
3     Tuesday           None 2013-01-01               576
4     Tuesday           None 2013-01-01               372
...       ...            ...        ...               ...
8568  Tuesday           None 2013-12-31              4504
8569  Tuesday           None 2013-12-31              3478
8570  Tuesday           None 2013-12-31              2711
8571  Tuesday           None 2013-12-31              2189
8572  Tuesday           None 2013-12-31              1457

[8573 rows x 8 columns]

I want to change the value in 'holiday' column to 'New Years Day' for those row which date is 2013-01-01, and run these codes BUT does not update:

from datetime import *
NYD=date(2013,1,1)
if df_subset.date is NYD:
    df_subset.replace('None','New Years Day')

Or are there better way to check date and update a cell in the dataframe?

Nov 9 in Python by Gkeace
• 130 points
27 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

How to sort Counter by value using python?

Use the Counter.most_common() method, it'll sort the items for you: >>> ...READ MORE

answered May 22, 2018 in Python by charlie_brown
• 7,720 points
2,157 views
0 votes
1 answer

How to sort dictionary by value python

This would work: d = sorted(data, key = ...READ MORE

answered Nov 2, 2018 in Python by Nabarupa
79 views
0 votes
1 answer
0 votes
1 answer

Not able to print cell value by index.

You have wrongly indexed. The index you ...READ MORE

answered Apr 8 in Python by Ganesh
23 views
0 votes
1 answer

Deleting a list element by value

Use the remove() function: >>> p = [1, ...READ MORE

answered May 11, 2018 in Python by Hamartia's Mask
• 1,580 points
24 views
0 votes
1 answer

How do I sort a dictionary by value?

It is not possible to sort a ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 56,960 points
37 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 394 views