I want to save and graph certain columns in Python using matplotlib. The argument for the columns will be obtained from the cmdline, so I'll have to use sys.argv to obtain them. Here's what I have currently:
EDIT: I should also mention that the column numbers can vary depending on what the user chooses. For instance, they could do just columns 1, 2
or just columns 1
.
with open('./P14_data.csv', 'rb') as csvfile:
data = csv.reader(csvfile, delimiter=';')
cols = [index for index in sys.argv[1:]]
#I want to extract the columns corresponding to cols
for col in cols:
x[col] = [rows for rows in data]
print x
But this returns an empty list [].
As for the output, I'd like to graph each column as a one-dimensional array. So for instance, with a csv file of the form:
1 5
1 3
0 2
0 3
1 1
1 3
If a user inputs '1', I want my code to save only column one variables in an array:
data = [[1, 1, 0, 0,..]]
plt.plot(data)
I know pandas is a valid option, but I like to learn it this way first. Thanks!
plt.plot(x)
plt.show()
where x is a one-dimensional array of the columns[['4,7,3,3]]