4

I have a dataframe that is indexed by a datetime column and I get value_count() for various time ranges. For example,

data['leadsource_ch_disp_name'].ix[rng[0]].value_counts()

returns

Unknown        223
Sponsorship    889
Reseller       145
Referral        52
dtype: int64

which is a series. I want to do this with 5 different time ranges (rng[i] for i=[0,..,4]). So then I am left with 5 series. What I want to do is plot these 5 series (on the same plot) such that the x-axis is the series name and the y-axis is the values. And I want it to be a line graph with 4 lines (for unknown, sponsorship, reseller, and referral).

I have tried the following

rng0=data['leadsource_ch_disp_name'].ix[rng[0]].value_counts()
rng1=data['leadsource_ch_disp_name'].ix[rng[1]].value_counts()
rng2=data['leadsource_ch_disp_name'].ix[rng[2]].value_counts()
rng3=data['leadsource_ch_disp_name'].ix[rng[3]].value_counts()
rng4=data['leadsource_ch_disp_name'].ix[rng[4]].value_counts()
rng5=data['leadsource_ch_disp_name'].ix[rng[5]].value_counts()
pd.concat([rng0,rng1,rng2,rng3,rng4,rng5],axis=1).plot()

however, this does not return what I want. This creates a plot where the x-axis is Referral,reseller,sponsorship,unknown and there are 5 lines for the 5 different series.

1 Answer 1

3

Since plot() draws a line for each column, try transposing the frame first..

pd.concat([rng0,rng1,rng2,rng3,rng4,rng5],axis=1).T.plot()
Sign up to request clarification or add additional context in comments.

1 Comment

Wow. I thought it would be more complicated than that :) Thanks!

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.