Monday, August 17, 2020

Series Methods

DataAnalysis with Python pandas - .head() and .tail() method of ...

Let’s first get a series of the “Age” column from our scientists dataframe.

# get the 'Age' column
ages = scientists['Age']
print(ages)

Output

Rosaline Franklin 37
William Gosset 61
Name: Age, dtype: int64

Numpy is a scientific computing library that typically deals with numeric vectors. Since a Series can be
thought of as an extension to the numpy.ndarray, there is an overlap of attributes and methods. When we have a vector of numbers, there are common calculations we can perform.

print(ages.mean())
49.0
print(ages.min())
37
print(ages.max())
61
print(ages.std())
16.9705627485 

The mean, min, max, and std are also methods in the numpy.ndarray.5 Some Series methods are
listed below:

  • append Concatenates two or more Series
  • corr Calculate a correlation with another Series*
  • cov Calculate a covariance with another Series*
  • describe Calculate summary statistics*
  • drop_duplicates Returns a Series without duplicates
  • equals Determines whether a Series has the same elements
  • get_values Get values of the Series; same as the values attribute
  • hist Draw a histogram
  • isin Checks whether values are contained in a Series
  • min Returns the minimum value
  • max Returns the maximum value
  • mean Returns the arithmetic mean
  • median Returns the median
  • mode Returns the mode(s)
  • quantile Returns the value at a given quantile
  • replace Replaces values in the Series with a specified value
  • sample Returns a random sample of values from the Series
  • sort_values Sorts values
  • to_frame Converts a Series to a DataFrame
  • transpose Returns the transpose
  • unique Returns a numpy.ndarray of unique values

* Indicates missing values will be automatically dropped.

Try to use these methods using our scientists dataframe. In the next post we'll discuss Boolean Subsetting in Series.

Share:

0 comments:

Post a Comment