from pandas import Series import pandas as pd print "These is a basic series array::\n" BasicSeries = Series([1, 10, 100, 1000]) print BasicSeries print BasicSeries.values print BasicSeries.index print "\n" print "A series with a predefined index:\n" IndexedSeries = Series([1, 4, 2, 1], index=['a', 'b', 'c', 'd']) print IndexedSeries print "A series created from a Python dict:\n" Dict2SeriesData = {'Monday': 2200, 'Tuesday': 3528, 'Wednesday': 123299, 'Thursday': 3234} Dict2Series = Series(Dict2SeriesData) print Dict2Series print "\n" print "Using the index to select a certain value:\n" print "Value c =",IndexedSeries['c'] print "\n" print "Using the index to see a certain value:\n" IndexedSeries['a'] = 14; print "Value c =",IndexedSeries['a'] print "\n" print "An index can be used in functions as a dict:\n" print "A Boolean evaluation: \n" print 'b' in IndexedSeries print "\n" print "You can sort a Series by providing the sorting order:\n" Days = ['Wednesday', 'Friday', 'Monday', 'Tuesday'] SortedDays = Series(Dict2SeriesData, index=Days) print SortedDays print "Note: Pandas wil assign a NaN to any values it does not find." print "\n" print "You combine two series into a single one, through mathematical operations:\n" Dict3SeriesData = {'Monday': 1400, 'Tuesday': 10000, 'Wednesday': 5, 'Sunday': 2365} Dict3Series = Series(Dict3SeriesData) Dailies = Dict3Series + Dict2Series print Dailies #page 114