How to calculate a series using Pandas

I have this series:

print series.head()
print type(series)
print series.index

year
1992    36.222222
1993    53.200000
1994    49.400000
1995    34.571429
1996    39.200000
Name: ranking, dtype: float64
<class 'pandas.core.series.Series'>

Int64Index([1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014], dtype='int64', name=u'year')

I'm trying to make a scatter plot, but I'm having problems accessing the index and values ​​from the series.

Any pointers would be appreciated.

+14
source share
4 answers

I believe the pandas series does not support kind = 'scatter' if you look at t0 on the .plot () call in the series.

I believe Leo's answer is better and suitable for use with pandas. I use mplotlib pyplot and it works similarly to its example.

import matplotlib.pyplot as plt
plt.scatter(ser.index, ser)
plt.show()

Perhaps try the following:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1)

year = [1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014]
value = np.random.rand(23)

ser =  pd.Series(index = year,data=value)
df =ser.to_frame()

df.reset_index(inplace=True)
df.columns = ['year','value']
df.plot(kind='scatter',x='year',y='value')
plt.show()

enter image description here

+19
source

I think the easiest

series.plot(style='.')
+22
source

?

import pylab
pylab.scatter(series.index, series)
+7

, , reset_index(), . .

, , :

df = series.reset_index()
df.plot(x="x_col", y="y_col", kind="scatter")
0

Source: https://habr.com/ru/post/1609048/


All Articles