Difference between revisions of "Python: Pandas - The Series Data Structure"

From MyWiki
Jump to: navigation, search
Line 62: Line 62:
 
s = pd.Series(sports)
 
s = pd.Series(sports)
 
s
 
s
 +
 +
 +
s.iloc[3]
 +
 +
 +
s.loc['Golf']
 +
 +
 +
s[3]
 +
 +
 +
s['Golf']
 +
 +
 +
sports = {99: 'Bhutan',
 +
          100: 'Scotland',
 +
          101: 'Japan',
 +
          102: 'South Korea'}
 +
s = pd.Series(sports)
 +
 +
  
  
 
</source>
 
</source>

Revision as of 15:29, 28 July 2019

import pandas as pd
pd.Series?
 
animals = ['Tiger', 'Bear', 'Moose']
pd.Series(animals)
 
 
numbers = [1, 2, 3]
pd.Series(numbers)
 
 
animals = ['Tiger', 'Bear', None]
pd.Series(animals)
 
numbers = [1, 2, None]
pd.Series(numbers)
 
 
import numpy as np
np.nan == None
 
 
np.nan == np.nan
 
 
np.isnan(np.nan)
 
 
 
sports = {'Archery': 'Bhutan',
          'Golf': 'Scotland',
          'Sumo': 'Japan',
          'Taekwondo': 'South Korea'}
s = pd.Series(sports)
s
 
s.index
 
 
s = pd.Series(['Tiger', 'Bear', 'Moose'], index=['India', 'America', 'Canada'])
s
 
 
sports = {'Archery': 'Bhutan',
          'Golf': 'Scotland',
          'Sumo': 'Japan',
          'Taekwondo': 'South Korea'}
s = pd.Series(sports, index=['Golf', 'Sumo', 'Hockey'])
s

Querying a series

sports = {'Archery': 'Bhutan',
          'Golf': 'Scotland',
          'Sumo': 'Japan',
          'Taekwondo': 'South Korea'}
s = pd.Series(sports)
s
 
 
s.iloc[3]
 
 
s.loc['Golf']
 
 
s[3]
 
 
s['Golf']
 
 
sports = {99: 'Bhutan',
          100: 'Scotland',
          101: 'Japan',
          102: 'South Korea'}
s = pd.Series(sports)