0

Given the data:

Column1; Column2; Column3
1; 4; 6
2; 2; 6
3; 3; 8
4; 1; 1
5; 4; 2

I can plot it via:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('test0.csv',delimiter='; ', engine='python')
titles = list(df)
for title in titles:
    if title == titles[0]:
        continue
    df.plot(titles[0],title, linestyle='--', marker='o')
    plt.savefig(title+'.png')

But if, instead, data was missing Column1 like:

Column2; Column3
4; 6
2; 6
3; 8
1; 1
4; 2

How do I plot it?

May be, something like df.plot(title, linestyle='--', marker='o')?

3
  • There are lot's of ways to plot it! I need a better understanding of what you are trying to plot. Commented Oct 9, 2016 at 0:25
  • I would like to plot Column2 X index, but index is missing. Commented Oct 9, 2016 at 7:25
  • 1
    @KcFnMi, IIUC, you could perform reset_index to set the DF's index to the default integer index and then pass Column2 as the y arg of the plot as: df.reset_index().plot(y='Column2', linestyle='--', marker='o') Commented Oct 9, 2016 at 8:01

1 Answer 1

2

I am not sure what you are trying to achieve but you could reset index and set it as you would like:

In[11]: df
Out[11]: 
   Column1   Column2   Column3
0        1         4         6
1        2         2         6
2        3         3         8
3        4         1         1
4        5         4         2

so if you want to plot col 2 as X axis and 3 as Y axis you could do something like:

df.set_index('Column2')['Column3'].plot()
Sign up to request clarification or add additional context in comments.

1 Comment

I'll accept an answer showing how to add and index column.

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.