Python: upsampling dataframe from daily to hourly data using ffill()
I'm trying to upsample my data from daily to hourly frequency and forward fill missing data.
I start with the following code:
df1 = pd.read_csv("DATA.csv")
df1.head(5)
I then used the following to convert to a datetime string and set the date/time as an index:
df1['DT'] = pd.to_datetime(df1['DT']).dt.strftime('%Y-%m-%d %H:%M:%S')
df1.set_index('DT')
I try to resample hourly as follows:
df1['DT'] = df1.resample('H').ffill()
But I get the following error:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or
PeriodIndex, but got an instance of 'RangeIndex'
I thought my dtype was already date time as instructed by the pd.to_datetime code above. Nothing I try seems to be working. Can anyone please help me?
My expected output is as follows:
DT VALUE
2016-08-01 00:00:00 0.000000
2016-08-01 01:00:00 0.000000
2016-08-01 02:00:00 0.000000
etc.
The file itself has approximately 1000 rows. The first 50 rows or so are zero so to clarify where there's actual data:
DT VALUE
2018-12-13 00:00:00 24000.000000
2018-12-13 01:00:00 24000.000000
2018-12-13 02:00:00 24000.000000
...
2018-12-13 23:00:00 24000.000000
2018-12-14 00:00:00 26000.000000
2018-12-14 01:00:00 26000.000000
etc.
python pandas
add a comment |
I'm trying to upsample my data from daily to hourly frequency and forward fill missing data.
I start with the following code:
df1 = pd.read_csv("DATA.csv")
df1.head(5)
I then used the following to convert to a datetime string and set the date/time as an index:
df1['DT'] = pd.to_datetime(df1['DT']).dt.strftime('%Y-%m-%d %H:%M:%S')
df1.set_index('DT')
I try to resample hourly as follows:
df1['DT'] = df1.resample('H').ffill()
But I get the following error:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or
PeriodIndex, but got an instance of 'RangeIndex'
I thought my dtype was already date time as instructed by the pd.to_datetime code above. Nothing I try seems to be working. Can anyone please help me?
My expected output is as follows:
DT VALUE
2016-08-01 00:00:00 0.000000
2016-08-01 01:00:00 0.000000
2016-08-01 02:00:00 0.000000
etc.
The file itself has approximately 1000 rows. The first 50 rows or so are zero so to clarify where there's actual data:
DT VALUE
2018-12-13 00:00:00 24000.000000
2018-12-13 01:00:00 24000.000000
2018-12-13 02:00:00 24000.000000
...
2018-12-13 23:00:00 24000.000000
2018-12-14 00:00:00 26000.000000
2018-12-14 01:00:00 26000.000000
etc.
python pandas
Mention your expected output.
– Abdur Rehman
Jan 2 at 18:14
@AbdurRehman Thanks for your comment, I've updated the original.
– GJB
Jan 2 at 18:28
Mentioncolumn_names
on data to make it more clear. Your actual data has year2018
and your expected data has year2016
.Is it right or mistyped ?
– Abdur Rehman
Jan 2 at 18:44
Thanks Abdur, I've updated the column names. There's about 3 years worth of data, preceded by mostly zeros. I've clarified it in the question.
– GJB
Jan 2 at 18:49
add a comment |
I'm trying to upsample my data from daily to hourly frequency and forward fill missing data.
I start with the following code:
df1 = pd.read_csv("DATA.csv")
df1.head(5)
I then used the following to convert to a datetime string and set the date/time as an index:
df1['DT'] = pd.to_datetime(df1['DT']).dt.strftime('%Y-%m-%d %H:%M:%S')
df1.set_index('DT')
I try to resample hourly as follows:
df1['DT'] = df1.resample('H').ffill()
But I get the following error:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or
PeriodIndex, but got an instance of 'RangeIndex'
I thought my dtype was already date time as instructed by the pd.to_datetime code above. Nothing I try seems to be working. Can anyone please help me?
My expected output is as follows:
DT VALUE
2016-08-01 00:00:00 0.000000
2016-08-01 01:00:00 0.000000
2016-08-01 02:00:00 0.000000
etc.
The file itself has approximately 1000 rows. The first 50 rows or so are zero so to clarify where there's actual data:
DT VALUE
2018-12-13 00:00:00 24000.000000
2018-12-13 01:00:00 24000.000000
2018-12-13 02:00:00 24000.000000
...
2018-12-13 23:00:00 24000.000000
2018-12-14 00:00:00 26000.000000
2018-12-14 01:00:00 26000.000000
etc.
python pandas
I'm trying to upsample my data from daily to hourly frequency and forward fill missing data.
I start with the following code:
df1 = pd.read_csv("DATA.csv")
df1.head(5)
I then used the following to convert to a datetime string and set the date/time as an index:
df1['DT'] = pd.to_datetime(df1['DT']).dt.strftime('%Y-%m-%d %H:%M:%S')
df1.set_index('DT')
I try to resample hourly as follows:
df1['DT'] = df1.resample('H').ffill()
But I get the following error:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or
PeriodIndex, but got an instance of 'RangeIndex'
I thought my dtype was already date time as instructed by the pd.to_datetime code above. Nothing I try seems to be working. Can anyone please help me?
My expected output is as follows:
DT VALUE
2016-08-01 00:00:00 0.000000
2016-08-01 01:00:00 0.000000
2016-08-01 02:00:00 0.000000
etc.
The file itself has approximately 1000 rows. The first 50 rows or so are zero so to clarify where there's actual data:
DT VALUE
2018-12-13 00:00:00 24000.000000
2018-12-13 01:00:00 24000.000000
2018-12-13 02:00:00 24000.000000
...
2018-12-13 23:00:00 24000.000000
2018-12-14 00:00:00 26000.000000
2018-12-14 01:00:00 26000.000000
etc.
python pandas
python pandas
edited Jan 2 at 18:48
GJB
asked Jan 2 at 17:47


GJBGJB
233
233
Mention your expected output.
– Abdur Rehman
Jan 2 at 18:14
@AbdurRehman Thanks for your comment, I've updated the original.
– GJB
Jan 2 at 18:28
Mentioncolumn_names
on data to make it more clear. Your actual data has year2018
and your expected data has year2016
.Is it right or mistyped ?
– Abdur Rehman
Jan 2 at 18:44
Thanks Abdur, I've updated the column names. There's about 3 years worth of data, preceded by mostly zeros. I've clarified it in the question.
– GJB
Jan 2 at 18:49
add a comment |
Mention your expected output.
– Abdur Rehman
Jan 2 at 18:14
@AbdurRehman Thanks for your comment, I've updated the original.
– GJB
Jan 2 at 18:28
Mentioncolumn_names
on data to make it more clear. Your actual data has year2018
and your expected data has year2016
.Is it right or mistyped ?
– Abdur Rehman
Jan 2 at 18:44
Thanks Abdur, I've updated the column names. There's about 3 years worth of data, preceded by mostly zeros. I've clarified it in the question.
– GJB
Jan 2 at 18:49
Mention your expected output.
– Abdur Rehman
Jan 2 at 18:14
Mention your expected output.
– Abdur Rehman
Jan 2 at 18:14
@AbdurRehman Thanks for your comment, I've updated the original.
– GJB
Jan 2 at 18:28
@AbdurRehman Thanks for your comment, I've updated the original.
– GJB
Jan 2 at 18:28
Mention
column_names
on data to make it more clear. Your actual data has year 2018
and your expected data has year 2016
.Is it right or mistyped ?– Abdur Rehman
Jan 2 at 18:44
Mention
column_names
on data to make it more clear. Your actual data has year 2018
and your expected data has year 2016
.Is it right or mistyped ?– Abdur Rehman
Jan 2 at 18:44
Thanks Abdur, I've updated the column names. There's about 3 years worth of data, preceded by mostly zeros. I've clarified it in the question.
– GJB
Jan 2 at 18:49
Thanks Abdur, I've updated the column names. There's about 3 years worth of data, preceded by mostly zeros. I've clarified it in the question.
– GJB
Jan 2 at 18:49
add a comment |
2 Answers
2
active
oldest
votes
Try assign it back
df1=df1.set_index('DT')
Or
df1.set_index('DT',inplace=True)
Hi W-B, thanks for your answer. I tried this out but unfortunately I'm still receiving the same error.
– GJB
Jan 2 at 18:01
df1.VALUE.resample('H').ffill() does this have errors @GJB
– Wen-Ben
Jan 2 at 18:10
I now get the issue AttributeError: 'DataFrame' object has no attribute 'VALUE'
– GJB
Jan 2 at 18:34
My mistake, I made a typo: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
– GJB
Jan 2 at 18:42
add a comment |
I am assuming some initial rows of your dataset as you mentioned,
DT VALUE
0 2016-08-01 0
1 2016-08-02 0
2 2016-08-03 0
3 2016-08-04 0
4 2016-08-05 0
5 2016-08-06 0
6 2016-08-07 0
7 2016-08-08 0
8 2016-08-09 0
Then, make index on DT
like this,
df = df.set_index('DT')
df
Output:
VALUE
DT
2016-08-01 0
2016-08-02 0
2016-08-03 0
2016-08-04 0
2016-08-05 0
2016-08-06 0
2016-08-07 0
2016-08-08 0
2016-08-09 0
Now, resample your dataframe,
df = df.resample('H').ffill()
df
Output: showing some initial values of output,
VALUE
DT
2016-08-01 00:00:00 0
2016-08-01 01:00:00 0
2016-08-01 02:00:00 0
2016-08-01 03:00:00 0
2016-08-01 04:00:00 0
2016-08-01 05:00:00 0
2016-08-01 06:00:00 0
2016-08-01 07:00:00 0
2016-08-01 08:00:00 0
2016-08-01 09:00:00 0
2016-08-01 10:00:00 0
@GJB let me know this worked for you or you have any other queries.
– Abdur Rehman
Jan 3 at 11:30
Hi Abdur, I got the following error: index must be monotonic increasing or decreasing
– GJB
Jan 4 at 11:40
I found the error- there was an errant NaN in the data right at the end. Many thanks Abdur.
– GJB
Jan 4 at 14:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54010877%2fpython-upsampling-dataframe-from-daily-to-hourly-data-using-ffill%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try assign it back
df1=df1.set_index('DT')
Or
df1.set_index('DT',inplace=True)
Hi W-B, thanks for your answer. I tried this out but unfortunately I'm still receiving the same error.
– GJB
Jan 2 at 18:01
df1.VALUE.resample('H').ffill() does this have errors @GJB
– Wen-Ben
Jan 2 at 18:10
I now get the issue AttributeError: 'DataFrame' object has no attribute 'VALUE'
– GJB
Jan 2 at 18:34
My mistake, I made a typo: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
– GJB
Jan 2 at 18:42
add a comment |
Try assign it back
df1=df1.set_index('DT')
Or
df1.set_index('DT',inplace=True)
Hi W-B, thanks for your answer. I tried this out but unfortunately I'm still receiving the same error.
– GJB
Jan 2 at 18:01
df1.VALUE.resample('H').ffill() does this have errors @GJB
– Wen-Ben
Jan 2 at 18:10
I now get the issue AttributeError: 'DataFrame' object has no attribute 'VALUE'
– GJB
Jan 2 at 18:34
My mistake, I made a typo: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
– GJB
Jan 2 at 18:42
add a comment |
Try assign it back
df1=df1.set_index('DT')
Or
df1.set_index('DT',inplace=True)
Try assign it back
df1=df1.set_index('DT')
Or
df1.set_index('DT',inplace=True)
answered Jan 2 at 17:50


Wen-BenWen-Ben
121k83571
121k83571
Hi W-B, thanks for your answer. I tried this out but unfortunately I'm still receiving the same error.
– GJB
Jan 2 at 18:01
df1.VALUE.resample('H').ffill() does this have errors @GJB
– Wen-Ben
Jan 2 at 18:10
I now get the issue AttributeError: 'DataFrame' object has no attribute 'VALUE'
– GJB
Jan 2 at 18:34
My mistake, I made a typo: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
– GJB
Jan 2 at 18:42
add a comment |
Hi W-B, thanks for your answer. I tried this out but unfortunately I'm still receiving the same error.
– GJB
Jan 2 at 18:01
df1.VALUE.resample('H').ffill() does this have errors @GJB
– Wen-Ben
Jan 2 at 18:10
I now get the issue AttributeError: 'DataFrame' object has no attribute 'VALUE'
– GJB
Jan 2 at 18:34
My mistake, I made a typo: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
– GJB
Jan 2 at 18:42
Hi W-B, thanks for your answer. I tried this out but unfortunately I'm still receiving the same error.
– GJB
Jan 2 at 18:01
Hi W-B, thanks for your answer. I tried this out but unfortunately I'm still receiving the same error.
– GJB
Jan 2 at 18:01
df1.VALUE.resample('H').ffill() does this have errors @GJB
– Wen-Ben
Jan 2 at 18:10
df1.VALUE.resample('H').ffill() does this have errors @GJB
– Wen-Ben
Jan 2 at 18:10
I now get the issue AttributeError: 'DataFrame' object has no attribute 'VALUE'
– GJB
Jan 2 at 18:34
I now get the issue AttributeError: 'DataFrame' object has no attribute 'VALUE'
– GJB
Jan 2 at 18:34
My mistake, I made a typo: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
– GJB
Jan 2 at 18:42
My mistake, I made a typo: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
– GJB
Jan 2 at 18:42
add a comment |
I am assuming some initial rows of your dataset as you mentioned,
DT VALUE
0 2016-08-01 0
1 2016-08-02 0
2 2016-08-03 0
3 2016-08-04 0
4 2016-08-05 0
5 2016-08-06 0
6 2016-08-07 0
7 2016-08-08 0
8 2016-08-09 0
Then, make index on DT
like this,
df = df.set_index('DT')
df
Output:
VALUE
DT
2016-08-01 0
2016-08-02 0
2016-08-03 0
2016-08-04 0
2016-08-05 0
2016-08-06 0
2016-08-07 0
2016-08-08 0
2016-08-09 0
Now, resample your dataframe,
df = df.resample('H').ffill()
df
Output: showing some initial values of output,
VALUE
DT
2016-08-01 00:00:00 0
2016-08-01 01:00:00 0
2016-08-01 02:00:00 0
2016-08-01 03:00:00 0
2016-08-01 04:00:00 0
2016-08-01 05:00:00 0
2016-08-01 06:00:00 0
2016-08-01 07:00:00 0
2016-08-01 08:00:00 0
2016-08-01 09:00:00 0
2016-08-01 10:00:00 0
@GJB let me know this worked for you or you have any other queries.
– Abdur Rehman
Jan 3 at 11:30
Hi Abdur, I got the following error: index must be monotonic increasing or decreasing
– GJB
Jan 4 at 11:40
I found the error- there was an errant NaN in the data right at the end. Many thanks Abdur.
– GJB
Jan 4 at 14:59
add a comment |
I am assuming some initial rows of your dataset as you mentioned,
DT VALUE
0 2016-08-01 0
1 2016-08-02 0
2 2016-08-03 0
3 2016-08-04 0
4 2016-08-05 0
5 2016-08-06 0
6 2016-08-07 0
7 2016-08-08 0
8 2016-08-09 0
Then, make index on DT
like this,
df = df.set_index('DT')
df
Output:
VALUE
DT
2016-08-01 0
2016-08-02 0
2016-08-03 0
2016-08-04 0
2016-08-05 0
2016-08-06 0
2016-08-07 0
2016-08-08 0
2016-08-09 0
Now, resample your dataframe,
df = df.resample('H').ffill()
df
Output: showing some initial values of output,
VALUE
DT
2016-08-01 00:00:00 0
2016-08-01 01:00:00 0
2016-08-01 02:00:00 0
2016-08-01 03:00:00 0
2016-08-01 04:00:00 0
2016-08-01 05:00:00 0
2016-08-01 06:00:00 0
2016-08-01 07:00:00 0
2016-08-01 08:00:00 0
2016-08-01 09:00:00 0
2016-08-01 10:00:00 0
@GJB let me know this worked for you or you have any other queries.
– Abdur Rehman
Jan 3 at 11:30
Hi Abdur, I got the following error: index must be monotonic increasing or decreasing
– GJB
Jan 4 at 11:40
I found the error- there was an errant NaN in the data right at the end. Many thanks Abdur.
– GJB
Jan 4 at 14:59
add a comment |
I am assuming some initial rows of your dataset as you mentioned,
DT VALUE
0 2016-08-01 0
1 2016-08-02 0
2 2016-08-03 0
3 2016-08-04 0
4 2016-08-05 0
5 2016-08-06 0
6 2016-08-07 0
7 2016-08-08 0
8 2016-08-09 0
Then, make index on DT
like this,
df = df.set_index('DT')
df
Output:
VALUE
DT
2016-08-01 0
2016-08-02 0
2016-08-03 0
2016-08-04 0
2016-08-05 0
2016-08-06 0
2016-08-07 0
2016-08-08 0
2016-08-09 0
Now, resample your dataframe,
df = df.resample('H').ffill()
df
Output: showing some initial values of output,
VALUE
DT
2016-08-01 00:00:00 0
2016-08-01 01:00:00 0
2016-08-01 02:00:00 0
2016-08-01 03:00:00 0
2016-08-01 04:00:00 0
2016-08-01 05:00:00 0
2016-08-01 06:00:00 0
2016-08-01 07:00:00 0
2016-08-01 08:00:00 0
2016-08-01 09:00:00 0
2016-08-01 10:00:00 0
I am assuming some initial rows of your dataset as you mentioned,
DT VALUE
0 2016-08-01 0
1 2016-08-02 0
2 2016-08-03 0
3 2016-08-04 0
4 2016-08-05 0
5 2016-08-06 0
6 2016-08-07 0
7 2016-08-08 0
8 2016-08-09 0
Then, make index on DT
like this,
df = df.set_index('DT')
df
Output:
VALUE
DT
2016-08-01 0
2016-08-02 0
2016-08-03 0
2016-08-04 0
2016-08-05 0
2016-08-06 0
2016-08-07 0
2016-08-08 0
2016-08-09 0
Now, resample your dataframe,
df = df.resample('H').ffill()
df
Output: showing some initial values of output,
VALUE
DT
2016-08-01 00:00:00 0
2016-08-01 01:00:00 0
2016-08-01 02:00:00 0
2016-08-01 03:00:00 0
2016-08-01 04:00:00 0
2016-08-01 05:00:00 0
2016-08-01 06:00:00 0
2016-08-01 07:00:00 0
2016-08-01 08:00:00 0
2016-08-01 09:00:00 0
2016-08-01 10:00:00 0
answered Jan 2 at 18:59


Abdur RehmanAbdur Rehman
626511
626511
@GJB let me know this worked for you or you have any other queries.
– Abdur Rehman
Jan 3 at 11:30
Hi Abdur, I got the following error: index must be monotonic increasing or decreasing
– GJB
Jan 4 at 11:40
I found the error- there was an errant NaN in the data right at the end. Many thanks Abdur.
– GJB
Jan 4 at 14:59
add a comment |
@GJB let me know this worked for you or you have any other queries.
– Abdur Rehman
Jan 3 at 11:30
Hi Abdur, I got the following error: index must be monotonic increasing or decreasing
– GJB
Jan 4 at 11:40
I found the error- there was an errant NaN in the data right at the end. Many thanks Abdur.
– GJB
Jan 4 at 14:59
@GJB let me know this worked for you or you have any other queries.
– Abdur Rehman
Jan 3 at 11:30
@GJB let me know this worked for you or you have any other queries.
– Abdur Rehman
Jan 3 at 11:30
Hi Abdur, I got the following error: index must be monotonic increasing or decreasing
– GJB
Jan 4 at 11:40
Hi Abdur, I got the following error: index must be monotonic increasing or decreasing
– GJB
Jan 4 at 11:40
I found the error- there was an errant NaN in the data right at the end. Many thanks Abdur.
– GJB
Jan 4 at 14:59
I found the error- there was an errant NaN in the data right at the end. Many thanks Abdur.
– GJB
Jan 4 at 14:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54010877%2fpython-upsampling-dataframe-from-daily-to-hourly-data-using-ffill%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Mention your expected output.
– Abdur Rehman
Jan 2 at 18:14
@AbdurRehman Thanks for your comment, I've updated the original.
– GJB
Jan 2 at 18:28
Mention
column_names
on data to make it more clear. Your actual data has year2018
and your expected data has year2016
.Is it right or mistyped ?– Abdur Rehman
Jan 2 at 18:44
Thanks Abdur, I've updated the column names. There's about 3 years worth of data, preceded by mostly zeros. I've clarified it in the question.
– GJB
Jan 2 at 18:49