1 Help on module dbase:
2
3 NAME
4 dbase
5
6 FILE
7 ./dbase.py
8
9 CLASSES
10 dbase
11
12 class dbase
13 | Author: Vincent Nijs (+ ?)
14 | Email: v-nijs at kellogg.northwestern.edu
15 | Last Modified: Sun Jan 7 10:05:12 CST 2007
16 |
17 | Todo:
18 | - Check if shelve loading/saving works
19 | - Only tested on Mac OS X 10.4.8, with full matplotlib (incl. pytz)
20 |
21 | Dependencies:
22 | - See import statement at the top of this file
23 |
24 | Doc:
25 | A simple data-frame, that reads and writes csv/pickle/shelve files with variable names.
26 | Data is stored in a dictionary.
27 |
28 | To use the class:
29 |
30 | >>> from dbase import dbase
31 | >>> y = dbase('your_filename.csv')
32 |
33 | or for a previously created dbase object stored in a pickle file
34 |
35 | >>> from dbase import dbase
36 | >>> y = dbase('your_filename.pickle')
37 |
38 | or without importing the dbase class
39 |
40 | >>> import cPickle
41 | >>> f = open('your_filename.pickle','rb')
42 | >>> y = cPickle.load(f)
43 | >>> data_key = cPickle.load(f)
44 | >>> f.close()
45 |
46 | or for a dictionary stored in a shelf file
47 |
48 | >>> from dbase import dbase
49 | >>> y = dbase('your_filename.pickle')
50 |
51 | To return a list of variable names and an array of data
52 |
53 | >>> varnm, data = y.get()
54 |
55 | For usage examples of other class methods see the class tests at the bottom of this file. To see the class in action
56 | simply run the file using 'python dbase.py'. This will generate some simulated data (data.csv) and save instance data
57 | of the class to a pickle file.
58 |
59 | Methods defined here:
60 |
61 | __init__(self, fname, *var, **date)
62 | Initializing the dbase class. Loading file fname.
63 |
64 | If you have have a column in your csv file that is a date-string use:
65 |
66 | >>> x = dbase('myfile.csv',date = 0)
67 |
68 | where 0 is the index of the date column
69 |
70 | If you have have an array in your pickle file that is a date variable use:
71 |
72 | >>> x = dbase('myfile.pickle',date = 'date')
73 |
74 | where 'date' is the key of the date array
75 |
76 | add_dummy(self, dum, dname='dummy')
77 |
78 | add_seasonal_dummies(self, freq=52, ndum=13)
79 | This function will only work if the freq and ndum 'fit. That is,
80 | weeks and 4-weekly periods will work. Weeks and months/quarters
81 | will not.
82 |
83 | add_trend(self, tname='trend')
84 |
85 | dataplot(self, *var, **adict)
86 | Plotting the data with variable names
87 |
88 | delobs(self, sel)
89 | Deleting specified observations, changing dictionary in place
90 |
91 | delobs_copy(self, sel)
92 | Deleting specified observations, making a copy
93 |
94 | delvar(self, *var)
95 | Deleting specified variables in the data dictionary, changing dictionary in place
96 |
97 | delvar_copy(self, *var)
98 | Deleting specified variables in the data dictionary, making a copy
99 |
100 | get(self, *var, **sel)
101 | Copying data and keys of selected variables for further analysis
102 |
103 | info(self, *var, **adict)
104 | Printing descriptive statistics on selected variables
105 |
106 | keepobs(self, sel)
107 | Keeping specified observations, changing dictionary in place
108 |
109 | keepobs_copy(self, sel)
110 | Keeping specified observations, making a copy
111 |
112 | keepvar(self, *var)
113 | Keeping specified variables in the data dictionary, changing dictionary in place
114 |
115 | keepvar_copy(self, *var)
116 | Keeping specified variables in the data dictionary, making a copy
117 |
118 | load(self, fname, var, date)
119 | Loading data from a csv or a pickle file of the dbase class.
120 | If this is csv file use pylab's load function. Seems much faster
121 | than scipy.io.read_array.
122 |
123 | load_csv(self, f)
124 | Loading data from a csv file. Uses pylab's load function. Seems much faster
125 | than scipy.io.read_array.
126 |
127 | load_pickle(self, f)
128 | Loading data from a created earlier using the the dbase class.
129 |
130 | load_shelve(self, fname, var)
131 | Loading data from a created earlier using the the dbase class.
132 |
133 | save(self, fname)
134 | Dumping the class data dictionary into a csv or pickle file
135 |
136 | save_csv(self, f)
137 | Dumping the class data dictionary into a csv file
138 |
139 | save_pickle(self, f)
140 | Dumping the class data dictionary and date_key into a binary pickle file
141 |
142 | save_shelve(self, fname)
143 | Dumping the class data dictionary into a shelve file
144
145 FUNCTIONS
146 arange(...)
147 arange([start,] stop[, step,], dtype=None)
148
149 For integer arguments, just like range() except it returns an array
150 whose type can be specified by the keyword argument dtype. If dtype
151 is not specified, the type of the result is deduced from the type of
152 the arguments.
153
154 For floating point arguments, the length of the result is ceil((stop -
155 start)/step). This rule may result in the last element of the result
156 being greater than stop.
157
158 array(...)
159 array(object, dtype=None, copy=1,order=None, subok=0,ndmin=0)
160
161 Return an array from object with the specified date-type.
162
163 Inputs:
164 object - an array, any object exposing the array interface, any
165 object whose __array__ method returns an array, or any
166 (nested) sequence.
167 dtype - The desired data-type for the array. If not given, then
168 the type will be determined as the minimum type required
169 to hold the objects in the sequence. This argument can only
170 be used to 'upcast' the array. For downcasting, use the
171 .astype(t) method.
172 copy - If true, then force a copy. Otherwise a copy will only occur
173 if __array__ returns a copy, obj is a nested sequence, or
174 a copy is needed to satisfy any of the other requirements
175 order - Specify the order of the array. If order is 'C', then the
176 array will be in C-contiguous order (last-index varies the
177 fastest). If order is 'FORTRAN', then the returned array
178 will be in Fortran-contiguous order (first-index varies the
179 fastest). If order is None, then the returned array may
180 be in either C-, or Fortran-contiguous order or even
181 discontiguous.
182 subok - If True, then sub-classes will be passed-through, otherwise
183 the returned array will be forced to be a base-class array
184 ndmin - Specifies the minimum number of dimensions that the resulting
185 array should have. 1's will be pre-pended to the shape as
186 needed to meet this requirement.
187
188 randn(...)
189 Returns zero-mean, unit-variance Gaussian random numbers in an
190 array of shape (d0, d1, ..., dn).
191
192 randn(d0, d1, ..., dn) -> random values
193
194 Note: This is a convenience function. If you want an
195 interface that takes a tuple as the first argument
196 use numpy.random.standard_normal(shape_tuple).
197
198 DATA
199 c_ = <numpy.lib.index_tricks.c_class object at 0x1186530>
200 division = _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192...