Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot multiple rows of a pandas dataframe

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

like image 312
ahajib Avatar asked Feb 15 '18 19:02

ahajib


People also ask

How do you plot a multiple line graph from a DataFrame in Python?

MatPlotLib with Python Make a 2D potentially heterogeneous tabular data using Pandas DataFrame class, where the column are x, y and equation. Get the reshaped dataframe organized by the given index such as x, equation, and y. Use the plot() method to plot the lines. To display the figure, use show() method.

How do I print all rows in pandas?

Sometimes, we need to print all of the DataFrame's rows after constructing the DataFrames in “pandas. The “pandas” provides the “pd. set_option()” method for printing all rows of the DataFrame. We may use this technique for printing all rows of the DataFrame on the terminal.

Can DataFrame contain multiple series?

Series can only contain single list with index, whereas dataframe can be made of more than one series or we can say that a dataframe is a collection of series that can be used to analyse the data.


2 Answers

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

df.T.plot()

enter image description here

like image 113
Vaishali Avatar answered Sep 28 '22 10:09

Vaishali


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

like image 24
EHB Avatar answered Sep 28 '22 11:09

EHB