I am working with time-series data and the sample of dataframe is as below.
Input data:
| date || Device_Id | | value |
| ---------------- || --------- | | ----- |
| 28-12-2018 00:00 || d1 | | 0.014 |
| 28-12-2018 00:15 || d1 | | 0.012 |
| 28-12-2018 00:30 || d1 | | 0.012 |
| 28-12-2018 00:45 || d1 | | 0.014 |
| 28-12-2018 01:00 || d1 | | 0.012 |
| 28-12-2018 01:15 || d1 | | 0.012 |
| 28-12-2018 01:30 || d1 | | 0.012 |
| 28-12-2018 01:45 || d1 | | 0.012 |
| 28-12-2018 02:00 || d1 | | 0.014 |
| 28-12-2018 02:15 || d1 | | 0.012 |
| .... || d1 | | ... |
| . || . | | . |
| . || . | | . |
| 31-03-2019 23:45 || d2 | | . |
Expected output:
| date || Device_Id | | value |
| ---------------- || --------- | | ----- |
| 28-12-2018 00:00 || d1 | | 0.014 |
| 28-12-2018 00:15 || d1 | | 0.012 |
| 28-12-2018 00:30 || d1 | | 0.012 |
| 28-12-2018 00:45 || d1 | | 0.014 |
| 28-12-2018 01:00 || d1 | | 0 |
| 28-12-2018 01:15 || d1 | | 0 |
| 28-12-2018 01:30 || d1 | | 0 |
| 28-12-2018 01:45 || d1 | | 0 |
| 28-12-2018 02:00 || d1 | | 0 |
| 28-12-2018 02:15 || d1 | | 0 |
| .... || d1 | | ... |
| . || . | | . |
| . || . | | . |
| 31-03-2019 23:45 || d2 | | . |
I want to replace zero value in the original dataframe based on Device_Id, date, and time between 1am to 6am. I have tried to solve the problem in different ways but unable to get the desired results. Below is my code that I have tried.
data1['value']=data1.loc[(data1['Device_Id'].str.contains('d1') & data1['date'].str.contains('28-12-2018')), 'value'].between_time('01:00:00', '06:00:00') = 0
The above code showing error "can't assign to function call". After that, I tried with below.
data1['value']=data1.loc[(data1['Device_Id'].str.contains('d1') & data1['date'].str.contains('28-12-2018')), 'value'].between_time('01:00:00', '06:00:00') * 0
This works but not updating the original dataframe.