messymon
messymon

Reputation: 33

Plotting DataFrame Python for specific rows & Columns

I am new to maplotlib & DataFrame.

I want to plot data from a csv file that I select from filedialog.askopenfile. The final plan is to plot each row inside the csv file, one by one (not all at the same time), so row 1 is plotted for a few seconds, then replaced by row 2, etc.

Here's the example of what inside the csv file:

enter image description here

I want to plot Row 4 and 5 but only starting on column D onward.

Currently. here's the code that I have:

   bmFile = filedialog.askopenfile(mode='r',
                                        filetypes=(("CSV file", "*.csv"), ("All files", "*.*")),
                                        title="Select a CSV file")

    bmFile2 = pd.read_csv(bmFile, header=[2])

    selectCol = bmFile2.iloc[0:,3:] 

When I tried to plot selectCol using plt.plot (selectCol) plt.show(), it plotted based on columns instead of rows (each line for each column), but I want to plot the other way around. Here's the example of the results (fail attempt) enter image description here

Could anyone please help me? I am trying my best to write this question as english is my second language. If it's not clear, please let me know.

Upvotes: 0

Views: 572

Answers (1)

Stef
Stef

Reputation: 30679

By default plotting is done columnwise, i.e. each column is one line. If you want to plot rowwise you can transpose the data. Pandas has its own convenience function for plotting. So you can write:

selectCol.T.plot()

Upvotes: 1

Related Questions