@@ -228,8 +228,8 @@ class DataFrame(NDFrame):
228
228
_het_axis = 1
229
229
230
230
_AXIS_NUMBERS = {
231
- 'index' : 0 ,
232
- 'columns' : 1
231
+ 'index' : 0 ,
232
+ 'columns' : 1
233
233
}
234
234
235
235
_AXIS_NAMES = dict ((v , k ) for k , v in _AXIS_NUMBERS .iteritems ())
@@ -246,8 +246,8 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
246
246
data : numpy ndarray (structured or homogeneous), dict, or DataFrame
247
247
Dict can contain Series, arrays, constants, or list-like objects
248
248
index : Index or array-like
249
- Index to use for resulting frame. Will default to np.arange(n) if no
250
- indexing information part of input data and no index provided
249
+ Index to use for resulting frame. Will default to np.arange(n) if
250
+ no indexing information part of input data and no index provided
251
251
columns : Index or array-like
252
252
Will default to np.arange(n) if not column labels provided
253
253
dtype : dtype, default None
@@ -257,7 +257,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
257
257
258
258
Examples
259
259
--------
260
- >>> d = {'col1' : ts1, 'col2' : ts2}
260
+ >>> d = {'col1': ts1, 'col2': ts2}
261
261
>>> df = DataFrame(data=d, index=index)
262
262
>>> df2 = DataFrame(np.random.randn(10, 5))
263
263
>>> df3 = DataFrame(np.random.randn(10, 5),
@@ -535,7 +535,8 @@ def __contains__(self, key):
535
535
# Python 2 division methods
536
536
if not py3compat .PY3 :
537
537
__div__ = _arith_method (operator .div , '__div__' , default_axis = None )
538
- __rdiv__ = _arith_method (lambda x , y : y / x , '__rdiv__' , default_axis = None )
538
+ __rdiv__ = _arith_method (lambda x , y : y / x , '__rdiv__' ,
539
+ default_axis = None )
539
540
540
541
def __neg__ (self ):
541
542
arr = operator .neg (self .values )
@@ -855,7 +856,7 @@ def _helper_csvexcel(self, writer, na_rep=None, cols=None, header=True,
855
856
index_label = []
856
857
for i , name in enumerate (self .index .names ):
857
858
if name is None :
858
- name = '' # 'level_%d' % i
859
+ name = ''
859
860
index_label .append (name )
860
861
else :
861
862
index_label = self .index .name
@@ -892,7 +893,7 @@ def _helper_csvexcel(self, writer, na_rep=None, cols=None, header=True,
892
893
if index :
893
894
if nlevels == 1 :
894
895
row_fields = [idx ]
895
- else : # handle MultiIndex
896
+ else : # handle MultiIndex
896
897
row_fields = list (idx )
897
898
for i , col in enumerate (cols ):
898
899
val = series [col ].get (idx )
@@ -960,8 +961,8 @@ def to_csv(self, path_or_buf, sep=",", na_rep='', cols=None,
960
961
if close :
961
962
f .close ()
962
963
963
- def to_excel (self , excel_writer , sheet_name = 'sheet1' , na_rep = '' , cols = None , header = True ,
964
- index = True , index_label = None ):
964
+ def to_excel (self , excel_writer , sheet_name = 'sheet1' , na_rep = '' ,
965
+ cols = None , header = True , index = True , index_label = None ):
965
966
"""
966
967
Write DataFrame to a excel sheet
967
968
@@ -987,8 +988,8 @@ def to_excel(self, excel_writer, sheet_name = 'sheet1', na_rep='', cols=None, he
987
988
Notes
988
989
-----
989
990
If passing an existing ExcelWriter object, then the sheet will be added
990
- to the existing workbook. This can be used to save different DataFrames
991
- to one workbook
991
+ to the existing workbook. This can be used to save different
992
+ DataFrames to one workbook
992
993
>>> writer = ExcelWriter('output.xlsx')
993
994
>>> df1.to_excel(writer,'sheet1')
994
995
>>> df2.to_excel(writer,'sheet2')
@@ -1000,8 +1001,9 @@ def to_excel(self, excel_writer, sheet_name = 'sheet1', na_rep='', cols=None, he
1000
1001
excel_writer = ExcelWriter (excel_writer )
1001
1002
need_save = True
1002
1003
excel_writer .cur_sheet = sheet_name
1003
- self ._helper_csvexcel (excel_writer , na_rep = na_rep , cols = cols , header = header ,
1004
- index = index , index_label = index_label , encoding = None )
1004
+ self ._helper_csvexcel (excel_writer , na_rep = na_rep , cols = cols ,
1005
+ header = header , index = index ,
1006
+ index_label = index_label , encoding = None )
1005
1007
if need_save :
1006
1008
excel_writer .save ()
1007
1009
@@ -1657,8 +1659,8 @@ def lookup(self, row_labels, col_labels):
1657
1659
1658
1660
def align (self , other , join = 'outer' , axis = None , level = None , copy = True ):
1659
1661
"""
1660
- Align two DataFrame object on their index and columns with the specified
1661
- join method for each axis Index
1662
+ Align two DataFrame object on their index and columns with the
1663
+ specified join method for each axis Index
1662
1664
1663
1665
Parameters
1664
1666
----------
@@ -2084,7 +2086,7 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None):
2084
2086
agg_obj = self
2085
2087
if subset is not None :
2086
2088
agg_axis_name = self ._get_axis_name (agg_axis )
2087
- agg_obj = self .reindex (** {agg_axis_name : subset })
2089
+ agg_obj = self .reindex (** {agg_axis_name : subset })
2088
2090
2089
2091
count = agg_obj .count (axis = agg_axis )
2090
2092
@@ -2102,7 +2104,7 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None):
2102
2104
2103
2105
labels = self ._get_axis (axis )
2104
2106
new_labels = labels [mask ]
2105
- return self .reindex (** {axis_name : new_labels })
2107
+ return self .reindex (** {axis_name : new_labels })
2106
2108
2107
2109
def drop_duplicates (self , cols = None , take_last = False ):
2108
2110
"""
@@ -2280,7 +2282,8 @@ def reorder_levels(self, order, axis=0):
2280
2282
-------
2281
2283
type of caller (new object)
2282
2284
"""
2283
- if not isinstance (self ._get_axis (axis ), MultiIndex ): # pragma: no cover
2285
+ if not isinstance (self ._get_axis (axis ),
2286
+ MultiIndex ): # pragma: no cover
2284
2287
raise Exception ('Can only reorder levels on a hierarchical axis.' )
2285
2288
2286
2289
result = self .copy ()
@@ -2751,7 +2754,8 @@ def asfreq(self, freq, method=None):
2751
2754
if isinstance (freq , datetools .DateOffset ):
2752
2755
dateRange = DateRange (self .index [0 ], self .index [- 1 ], offset = freq )
2753
2756
else :
2754
- dateRange = DateRange (self .index [0 ], self .index [- 1 ], time_rule = freq )
2757
+ dateRange = DateRange (self .index [0 ], self .index [- 1 ],
2758
+ time_rule = freq )
2755
2759
2756
2760
return self .reindex (dateRange , method = method )
2757
2761
@@ -2864,8 +2868,8 @@ def apply(self, func, axis=0, broadcast=False, raw=False,
2864
2868
2865
2869
Notes
2866
2870
-----
2867
- Function passed should not have side effects. If the result is a Series,
2868
- it should have the same index
2871
+ Function passed should not have side effects. If the result is a
2872
+ Series, it should have the same index
2869
2873
2870
2874
Returns
2871
2875
-------
@@ -3038,7 +3042,8 @@ def append(self, other, ignore_index=False, verify_integrity=True):
3038
3042
if isinstance (other , dict ):
3039
3043
other = Series (other )
3040
3044
if other .name is None and not ignore_index :
3041
- raise Exception ('Can only append a Series if ignore_index=True' )
3045
+ raise Exception ('Can only append a Series if '
3046
+ 'ignore_index=True' )
3042
3047
3043
3048
index = None if other .name is None else [other .name ]
3044
3049
other = other .reindex (self .columns , copy = False )
@@ -3114,7 +3119,7 @@ def _join_compat(self, other, on=None, how='left', lsuffix='', rsuffix='',
3114
3119
3115
3120
if isinstance (other , Series ):
3116
3121
assert (other .name is not None )
3117
- other = DataFrame ({other .name : other })
3122
+ other = DataFrame ({other .name : other })
3118
3123
3119
3124
if isinstance (other , DataFrame ):
3120
3125
return merge (self , other , left_on = on , how = how ,
@@ -3343,7 +3348,8 @@ def _count_level(self, level, axis=0, numeric_only=False):
3343
3348
if axis == 1 :
3344
3349
frame = frame .T
3345
3350
3346
- mask = notnull (frame .values ).view (np .uint8 ) # python 2.5
3351
+ # python 2.5
3352
+ mask = notnull (frame .values ).view (np .uint8 )
3347
3353
3348
3354
level_index = frame .index .levels [level ]
3349
3355
counts = lib .count_level_2d (mask , frame .index .labels [level ],
@@ -3687,8 +3693,8 @@ def boxplot(self, column=None, by=None, ax=None, fontsize=None,
3687
3693
"""
3688
3694
import pandas .tools .plotting as plots
3689
3695
import matplotlib .pyplot as plt
3690
- ax = plots .boxplot (self , column = column , by = by , ax = ax , fontsize = fontsize ,
3691
- grid = grid , rot = rot , ** kwds )
3696
+ ax = plots .boxplot (self , column = column , by = by , ax = ax ,
3697
+ fontsize = fontsize , grid = grid , rot = rot , ** kwds )
3692
3698
plt .draw_if_interactive ()
3693
3699
return ax
3694
3700
@@ -3791,7 +3797,7 @@ def _bar_plot(self, axes, subplots=False, use_index=True, grid=True,
3791
3797
bottom = np .zeros (N ), linewidth = 1 , ** kwds )
3792
3798
ax .set_title (col )
3793
3799
else :
3794
- rects .append (ax .bar (xinds + i * 0.5 / K , y , 0.5 / K ,
3800
+ rects .append (ax .bar (xinds + i * 0.5 / K , y , 0.5 / K ,
3795
3801
bottom = np .zeros (N ), label = col ,
3796
3802
color = colors [i % len (colors )], ** kwds ))
3797
3803
labels .append (col )
@@ -3907,7 +3913,7 @@ def group_agg(values, bounds, f):
3907
3913
else :
3908
3914
right_bound = bounds [i + 1 ]
3909
3915
3910
- result [i ] = f (values [left_bound : right_bound ])
3916
+ result [i ] = f (values [left_bound : right_bound ])
3911
3917
3912
3918
return result
3913
3919
@@ -4027,6 +4033,7 @@ def _rec_to_dict(arr):
4027
4033
4028
4034
return columns , sdict
4029
4035
4036
+
4030
4037
def _list_to_sdict (data , columns ):
4031
4038
if len (data ) > 0 and isinstance (data [0 ], tuple ):
4032
4039
content = list (lib .to_object_array_tuples (data ).T )
@@ -4039,6 +4046,7 @@ def _list_to_sdict(data, columns):
4039
4046
return {}, columns
4040
4047
return _convert_object_array (content , columns )
4041
4048
4049
+
4042
4050
def _list_of_dict_to_sdict (data , columns ):
4043
4051
if columns is None :
4044
4052
gen = (x .keys () for x in data )
@@ -4047,6 +4055,7 @@ def _list_of_dict_to_sdict(data, columns):
4047
4055
content = list (lib .dicts_to_array (data , list (columns )).T )
4048
4056
return _convert_object_array (content , columns )
4049
4057
4058
+
4050
4059
def _convert_object_array (content , columns ):
4051
4060
if columns is None :
4052
4061
columns = range (len (content ))
@@ -4059,6 +4068,7 @@ def _convert_object_array(content, columns):
4059
4068
for c , vals in zip (columns , content ))
4060
4069
return sdict , columns
4061
4070
4071
+
4062
4072
def _homogenize (data , index , columns , dtype = None ):
4063
4073
from pandas .core .series import _sanitize_array
4064
4074
@@ -4104,9 +4114,11 @@ def _homogenize(data, index, columns, dtype=None):
4104
4114
4105
4115
return homogenized
4106
4116
4117
+
4107
4118
def _put_str (s , space ):
4108
4119
return ('%s' % s )[:space ].ljust (space )
4109
4120
4121
+
4110
4122
def _is_sequence (x ):
4111
4123
try :
4112
4124
iter (x )
@@ -4115,6 +4127,7 @@ def _is_sequence(x):
4115
4127
except Exception :
4116
4128
return False
4117
4129
4130
+
4118
4131
def install_ipython_completers (): # pragma: no cover
4119
4132
"""Register the DataFrame type with IPython's tab completion machinery, so
4120
4133
that it knows about accessing column names as attributes."""
@@ -4125,6 +4138,7 @@ def complete_dataframe(obj, prev_completions):
4125
4138
return prev_completions + [c for c in obj .columns \
4126
4139
if isinstance (c , basestring ) and py3compat .isidentifier (c )]
4127
4140
4141
+
4128
4142
# Importing IPython brings in about 200 modules, so we want to avoid it unless
4129
4143
# we're in IPython (when those modules are loaded anyway).
4130
4144
if "IPython" in sys .modules : # pragma: no cover
@@ -4133,6 +4147,7 @@ def complete_dataframe(obj, prev_completions):
4133
4147
except Exception :
4134
4148
pass
4135
4149
4150
+
4136
4151
def _indexer_from_factorized (labels , shape , compress = True ):
4137
4152
from pandas .core .groupby import get_group_index , _compress_group_index
4138
4153
@@ -4149,6 +4164,7 @@ def _indexer_from_factorized(labels, shape, compress=True):
4149
4164
4150
4165
return indexer
4151
4166
4167
+
4152
4168
def _lexsort_indexer (keys ):
4153
4169
labels = []
4154
4170
shape = []
@@ -4163,6 +4179,7 @@ def _lexsort_indexer(keys):
4163
4179
shape .append (len (rizer .uniques ))
4164
4180
return _indexer_from_factorized (labels , shape )
4165
4181
4182
+
4166
4183
if __name__ == '__main__' :
4167
4184
import nose
4168
4185
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
0 commit comments