0

My Dataframe looks like this and i have to insert a few rows

 Date     AccessType    PrePaidSubsRev
 2013-11-01  1    584190
 2013-11-01  2    0
 2013-11-02  1    800020
 2013-11-02  2    0
 2013-11-03  1    705800
 2013-11-03  2    0
 2013-11-04  1    699930
 2013-11-04  3    0
 2013-11-04  2    0
 2013-11-05  1    963270
 2013-11-05  3    0
 2013-11-05  2    0
 2013-11-06  1    874530
 2013-11-06  3    0
 2013-11-06  2    0
 2013-11-07  1    886005
 2013-11-07  2    0
 2013-11-08  1    1209300
 2013-11-08  3    0
 2013-11-08  2    0
 2013-11-09  1    762560
 2013-11-09  2    0
 2013-11-10  1    489730
 2013-11-10  2    0
  1. For dates where the accesstype 3 is missing i have to insert rows with the same date and accesstype as 3 and PrePaidSubsRev value as 0 .

    If someone has any idea please go ahead.

1 Answer 1

2
>>> group = df.groupby(['Date','AccessType']).sum()
>>> temp = group.unstack()
>>> temp = temp.replace('nan',0)
>>> temp = temp1.stack()
>>> df = temp.reset_index()

This part worked for me..Thanks

Sign up to request clarification or add additional context in comments.

2 Comments

Hi i tried it out in Python 2.6.6 the replace command does not work there ,but in python 2.7 it works fine ..any help please feel free
The part temp = temp.replace('nan',0) is not working ,its not replacing nan with 0 in the groupby object and thanks for the response Roman

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.