Amarth Gûl
Amarth Gûl

Reputation: 1082

Get value of a column in pandas

I want to exact the value of a column in pandas and plot them, I coded like that:

traffic = pd.read_csv('traffic.csv')
traffic.columns = ['X', 'Y', 'Zone', 'Potential']
X = traffic.iloc[0:579, 0:1]['X']
Y = traffic.iloc[0:579, 1:2]['Y']
Z = traffic.iloc[0:579, 3:4]['Potential']

fig = plt.figure()
for x, y, z in zip(list(X), list(Y), list(Z)):
    plt.plot(x, y, 'ro', markersize = Z, alpha = 0.5)
plt.show()

And got a TypeError: cannot convert the series to <class 'float'>. Now it seems it gives me a data with tails or something (if I print() them in the bottom there'll be some Name: X, dtype:float64), so failed the for loop.

So how can I get the value of a column?

The data is like that(copied from the .csv file):

413 359 A   1.7
403 343 A   2.1
383.5   351 A   2.2
381 377.5   A   1.7
339 376 A   2.1
335 383 A   2.5
317 362 A   2.4
334.5   353.5   A   2.4
333 342 A   2.1
282 325 A   1.6
...

Upvotes: 1

Views: 104

Answers (1)

Thomas Grsp
Thomas Grsp

Reputation: 502

You can use pandas' matplotlib wrapper

traffic.plot(x='X', y='Y', style='ro', markersize='Potential', alpha=0.5)
plt.show()

Edit :

Apparently, pandas wrapper does not allow markersize to be variable.

Though, you can use a standard scatter plot :

plt.scatter(df['X'],df['Y'], s=df['Potential'])

Upvotes: 1

Related Questions