series_test(): Demonstrate the use of Series in pandas. Create a series: 0 6300 1 6650 2 6275 3 6400 dtype: int64 Print with a loop "for i in range ( 0, 4 ):" 6300 6650 6275 6400 Print with a generator "for length in river_lengths": 6300 6650 6275 6400 Print river_lengths.index: RangeIndex(start=0, stop=4, step=1) Specify river names as the index, and print river_lengths: Yangtze 6300 Nile 6650 Mississippi 6275 Amazon 6400 dtype: int64 Use a river name to index a river length: river_lengths['Nile'] = 6650 Specify index, name and dtype. Now print river_lengths Yangtze 6300.0 Nile 6650.0 Mississippi 6275.0 Amazon 6400.0 Name: Length (km), dtype: float64 Now print river_lengths["Nile"] 6650.0 Now print river_lengths["Yangtze":"Mississippi"] Yangtze 6300.0 Nile 6650.0 Mississippi 6275.0 Name: Length (km), dtype: float64 Filter the data. print ( river_lengths[river_lengths < 6500] ): Yangtze 6300.0 Mississippi 6275.0 Amazon 6400.0 Name: Length (km), dtype: float64 Make a new Series, "river_lengths_miles" river_lengths_miles = river_lengths * 0.621371 river_lengths_miles.name = "Length (miles)" Yangtze 3914.637300 Nile 4132.117150 Mississippi 3899.103025 Amazon 3976.774400 Name: Length (miles), dtype: float64 Series for mass of astronomical bodies: Ganymede 1.482000e+23 Callisto 1.076323e+00 Io 8.932000e+22 Europa 4.800000e+22 Moon 7.342000e+22 Earth 5.972000e+24 Name: mass (kg), dtype: float64 Series for radius of astronomical bodies: Ganymede 2634000.0 Io 1822000.0 Moon 1737000.0 Earth 6371000.0 Name: radius (m), dtype: float64 Create new series "gravity = G * mass / radius**2" Body Callisto NaN Earth 9.819973 Europa NaN Ganymede 1.425681 Io 1.795799 Moon 1.624129 Name: surface gravity m/s**2, dtype: float64 gravity.isnull() checks for NaN values. Body Callisto True Earth False Europa True Ganymede False Io False Moon False Name: surface gravity m/s**2, dtype: bool gravity = gravity.dropna() drops NaN entries. Body Earth 9.819973 Ganymede 1.425681 Io 1.795799 Moon 1.624129 Name: surface gravity m/s**2, dtype: float64 gravity_array = gravity.values creates numpy array. [9.81997343 1.42568108 1.79579887 1.6241288 ]