Pandas Lesson 3 Analyze a Series

  1. Create Series for this section
  2. Use name attribute to get Series name
  3. Use size attribute to get Series row count
  4. Use dtypes attribute to get Series data type
  5. Use describe() function to view Series Statistics
  6. Use the mean() function to view Series Mean
  7. Use the head() method to view a subset of Series data

1) Create Series for this Section

Let’s create a Series to analyze.

#import the pandas library
import pandas as pd

#create the Pandas Series include the Data, Name and index
grades = pd.Series([97,93,100,86,100,86,93,84,99],name = "history_grades", 
                   index = ["Henry","John","Jane","Henry","John","Jane","Henry","John","Jane"])
#display grades series
grades

#PRESS Shift + Enter
Notebook Output

2) Use name attribute to get Series name

Use the name attribute to get the name of the Series.

#get the name of the series
grades.name
Notebook Output

3) Use size attribute to get Series row count

grades.size
Notebook Output

4) Use dtypes attribute to get Series data type

grades.dtype
Notebook Output

5) Use describe() function to view Series Statistics

grades.describe()
Notebook Output

6) Use the mean() function to view Series Mean

grades.mean()
Notebook Output

7) Use the head() method to view a subset of Series data

The head() returns the first 5 elements of your series. You can also specify another number if your want more or less .

grades.head()#returns first 5 rows
grades.head(2)#returns first 2 rows
grades.head(-5)#excludes last 5
Notebook Output