0

I am trying to plot a line graph that is going to be fluctuating according to the column values.

My pandas dataframe has 10 columns which represent each day (names of my columns are day1, day2, ..., day10) and 3 rows which each one shows one single feature that I want to look at their changes daily(percentage of daily sales of potato, onion and strawberry).

I have already tried to plot it with

timeseries.plot()
pyplot.show()

what I get is : http://img4.imagetitan.com/img.php?image=19_problem.png

("Feature" in this pic is the index's column name and instead of 0,1,2 as row names I have Potato, Onion and Strawbery)

What I want to achieve for each row separately is: http://img4.imagetitan.com/img.php?image=19_question.png

I would be so happy if someone can help me with this. Thanks in advance

1
  • Can you provide a sample of your dataset ? Commented May 16, 2019 at 10:27

1 Answer 1

1

Try to transpose your dataframe:

timeseries.T.plot()

mcve:

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.random((3, 10)), columns=[f'day{i}' for i in range(10)], index=['Potato', 'Onion', 'Strawbery'])

               day0      day1      day2  ...      day7      day8      day9
Potato     0.232951  0.764059  0.876049  ...  0.631673  0.185351  0.139135
Onion      0.516356  0.149735  0.630793  ...  0.389646  0.111144  0.799737
Strawbery  0.768387  0.597404  0.335025  ...  0.950945  0.038993  0.996456

[3 rows x 10 columns]


df.T.plot()

enter image description here

if you wonder why, have a look at df.T:

df.T
        Potato     Onion  Strawbery
day0  0.232951  0.516356   0.768387
day1  0.764059  0.149735   0.597404
day2  0.876049  0.630793   0.335025
day3  0.442927  0.646496   0.034924
day4  0.794574  0.061397   0.385407
day5  0.517380  0.480174   0.979457
day6  0.068231  0.332127   0.272894
day7  0.631673  0.389646   0.950945
day8  0.185351  0.111144   0.038993
day9  0.139135  0.799737   0.996456
Sign up to request clarification or add additional context in comments.

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.