5

I have a pandas dataframe which looks like:

A    B    C    D
1    2    3    4
5    6    7    8
9    10   11   12

And I need to plot all three rows and not columns. I know I can use iloc if I want a specific row but looking for something that could plot all rows together:

df.iloc[0]

I have also tried:

df.plot()

which plots columns A,B,... instead of rows.

NOTE: Number of rows is variable for different dataframes and could be up to 200 so I am not interested in setting colors or stuff like that

2
  • 5
    do you need df.T.plot()? Commented Feb 15, 2018 at 19:52
  • @Vaishali That did the job, please post it as an answer Commented Feb 15, 2018 at 19:54

2 Answers 2

10

You can transpose the dataframe and then plot to plot the rows

df.T.plot()

enter image description here

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

1 Comment

@Vaishali- Is there away to do this without transposing the data? Because, if the dataframe is huge then transposing takes a lot of time.
2

So, you're plotting columns of data vs rows? Sounds like you need to transpose your dataframe. Use df.T.plot()

1 Comment

Data should always be structured with observations as rows, and categories as columns. I encourage you to read about "Tidy Data" to make your life MUCH easier down the road jeannicholashould.com/tidy-data-in-python.html

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.