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