Python Forum
Auto row increment code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Auto row increment code
#1
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
Reply
#2
So what have you tried?
Reply
#3
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use Python Packages to Increment a Column(not a row) ricmacharia 0 1,808 Jun-10-2019, 09:57 AM
Last Post: ricmacharia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020