Differences between revisions 6 and 7
Revision 6 as of 2012-10-24 16:29:19
Size: 1022
Editor: MikhailItkin
Comment:
Revision 7 as of 2012-10-24 16:29:35
Size: 1025
Editor: MikhailItkin
Comment:
Deletions are marked like this. Additions are marked like this.
Line 37: Line 37:
# Pandas is using numpy.na representation of not-a-number, while Nio returns masked arrays # Pandas is using numpy.na representation of not-a-number,
#
while Nio returns masked arrays

Pandas

  • Indexed arrays
  • DateFrame

  • DateRange

  • Indexing, slicing
  • Apply common numpy statistics
  • Data alignment

   1 import numpy as np
   2 import pandas as p
   3 import Nio
   4 
   5 
   6 nc1 = Nio.open_file('10147-precip.nc') # hamburg
   7 nc2 = Nio.open_file('10015-precip.nc') # helgoland
   8 
   9 time1 = nc1.variables['time'][:]
  10 time2 = nc2.variables['time'][:]
  11 
  12 rain1 = nc1.variables['rainfall_rate_hour'][:]
  13 rain2 = nc2.variables['rainfall_rate_hour'][:]
  14 
  15 
  16 # plot data 
  17 plot(rain1, 'g', rain2, 'b')
  18 
  19 # Timestamps shall be python dates
  20 dates1 = num2date(epoch2num(time1))
  21 dates2 = num2date(epoch2num(time2))
  22 
  23 # Indexed arrays - p.Series
  24 ds1 = p.Series(rain1, index = dates1)
  25 ds2 = p.Series(rain2, index = dates2)
  26 
  27 # Pandas is using numpy.na representation of not-a-number,
  28 # while Nio returns masked arrays
  29 # Many basic array operations are valid for pandas Series
  30 ds1 = np.where(ds1<0, nan, ds1)
  31 ds2 = np.where(ds2<0, nan, ds2)
  32 
  33 # plotting functions
  34 ds1.plot()
  35 ds2.plot()

LehreWiki: PythonCourse/PythonLES/Pandas (last edited 2012-11-05 10:53:39 by anonymous)