0

I have a simple csv dataframe as follow:

Date,Data
2000-01-31,9
2000-02-28,8
2000-03-31,7
2000-04-30,6
2000-05-31,5
2000-06-30,4
2000-07-31,3
2000-08-31,2
2000-09-30,1
2000-10-31,0
2000-11-30,11
2000-12-31,12

I would like to repeat this dataframe over 10 years, with the year stamp changing accordingly, as follow:

Date,Data
2000-01-31,9
2000-02-28,8
2000-03-31,7
2000-04-30,6
2000-05-31,5
2000-06-30,4
2000-07-31,3
2000-08-31,2
2000-09-30,1
2000-10-31,0
2000-11-30,11
2000-12-31,12
2001-01-31,9
2001-02-28,8
2001-03-31,7
2001-04-30,6
2001-05-31,5
2001-06-30,4
2001-07-31,3
2001-08-31,2
2001-09-30,1
2001-10-31,0
2001-11-30,11
2001-12-31,12
....

How can I do that?

2 Answers 2

2

You can just using concat

n=2
Newdf=pd.concat([df]*n,keys=range(n))
Newdf.Date+=pd.to_timedelta(Newdf.index.get_level_values(level=0),'Y')
Newdf.reset_index(level=0,drop=True, inplace=true)
Sign up to request clarification or add additional context in comments.

Comments

1

Try:

df1 = pd.concat([df] * 10)
date_fix =  pd.date_range(start='2000-01-31', freq='M', periods=len(df1))
df1['Date'] = date_fix
df1

[out]

    Date    Data
0   2000-01-31  9
1   2000-02-29  8
2   2000-03-31  7
3   2000-04-30  6
4   2000-05-31  5
5   2000-06-30  4
6   2000-07-31  3
... ... ...
5   2009-06-30  4
6   2009-07-31  3
7   2009-08-31  2
8   2009-09-30  1
9   2009-10-31  0
10  2009-11-30  11
11  2009-12-31  12

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.