Auto row increment code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Auto row increment code (/thread-29469.html) |
Auto row increment code - codesearcher - Sep-04-2020 Hi All, I have been given the data Date count 1/1/2020 1 2/1/2020 5 4/1/2020 10 6/1/2020 15 Here i need a python code to auto fill the missing dates against date & count should be previous month's value retained Date count 1/1/2020 1 2/1/2020 5 3/1/2020 5 4/1/2020 10 5/1/2020 10 6/1/2020 15 RE: Auto row increment code - ndc85430 - Sep-04-2020 So what have you tried? RE: Auto row increment code - codesearcher - Sep-04-2020 Time being I have used Autofill was working with Range function however am not able to retrieve previous month value.. import pandas as pd idx = pd.date_range('1/1/2020', '6/1/2020') s = pd.Series({'1/1/2020': 1, '2/1/2020': 5, '4/1/2020': 10, '6/1/2020': 15}) s.index = pd.DatetimeIndex(s.index) s = s.reindex(idx, fill_value=0) print(s) |