0

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.

1 Answer 1

1

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()
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.