Series¶arraySeries may have missing dataSeries operations ignore missing data by defaultSeries with Default Indices¶Series has integer indices numbered sequentially from 0import pandas as pd
grades = pd.Series([87, 100, 94])
Series with All Elements Having the Same Value¶array or a range) containing the Series’ indicespd.Series(98.6, range(3))
Series’ Elements¶grades[0]
Series provides many methods for common tasks including producing various descriptive statisticsgrades.count()
grades.mean()
grades.min()
grades.max()
grades.std()
Series method describe produces all these stats and more25%, 50% and 75% are quartiles:50% represents the median of the sorted values.25% represents the median of the first half of the sorted values.75% represents the median of the second half of the sorted values.grades.describe()
Series with Custom Indices¶Can specify custom indices with the index keyword argument
grades = pd.Series([87, 100, 94], index=['Wally', 'Eva', 'Sam'])
grades
Series with a dictionary, its keys are the indices, and its values become the Series’ element valuesgrades = pd.Series({'Wally': 87, 'Eva': 100, 'Sam': 94})
grades
Series Via Custom Indices¶grades['Eva']
Series as attributesgrades.Wally
dtype attribute returns the underlying array’s element typegrades.dtype
values attribute returns the underlying arraygrades.values
Series of strings, you can use str attribute to call string methods on the elementshardware = pd.Series(['Hammer', 'Saw', 'Wrench'])
hardware
contains on each elementSeries containing bool values indicating the contains method’s result for each elementstr attribute provides many string-processing methods that are similar to those in Python’s string type
hardware.str.contains('a')
upper to produce a new Series containing the uppercase versions of each element in hardwarehardware.str.upper()
©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 5 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.