@@ -1199,22 +1199,109 @@ numpy array. For instance,
1199
1199
dflookup = DataFrame(np.random.rand(20 ,4 ), columns = [' A' ,' B' ,' C' ,' D' ])
1200
1200
dflookup.lookup(list (range (0 ,10 ,2 )), [' B' ,' C' ,' A' ,' B' ,' D' ])
1201
1201
1202
- Setting values in mixed-type DataFrame
1203
- --------------------------------------
1202
+ .. _indexing.float64index :
1204
1203
1205
- .. _indexing.mixed_type_setting :
1204
+ Float64Index
1205
+ ------------
1206
+
1207
+ .. versionadded :: 0.13.0
1206
1208
1207
- Setting values on a mixed-type DataFrame or Panel is supported when using
1208
- scalar values, though setting arbitrary vectors is not yet supported:
1209
+ By default a ``Float64Index `` will be automatically created when passing floating, or mixed-integer-floating values in index creation.
1210
+ This enables a pure label-based slicing paradigm that makes ``[],ix,loc `` for scalar indexing and slicing work exactly the
1211
+ same.
1209
1212
1210
1213
.. ipython :: python
1211
1214
1212
- df2 = df[:4 ]
1213
- df2[' foo' ] = ' bar'
1214
- print (df2)
1215
- df2.ix[2 ] = np.nan
1216
- print (df2)
1217
- print (df2.dtypes)
1215
+ indexf = Index([1.5 , 2 , 3 , 4.5 , 5 ])
1216
+ indexf
1217
+ sf = Series(range (5 ),index = indexf)
1218
+ sf
1219
+
1220
+ Scalar selection for ``[],.ix,.loc `` will always be label based. An integer will match an equal float index (e.g. ``3 `` is equivalent to ``3.0 ``)
1221
+
1222
+ .. ipython :: python
1223
+
1224
+ sf[3 ]
1225
+ sf[3.0 ]
1226
+ sf.ix[3 ]
1227
+ sf.ix[3.0 ]
1228
+ sf.loc[3 ]
1229
+ sf.loc[3.0 ]
1230
+
1231
+ The only positional indexing is via ``iloc ``
1232
+
1233
+ .. ipython :: python
1234
+
1235
+ sf.iloc[3 ]
1236
+
1237
+ A scalar index that is not found will raise ``KeyError ``
1238
+
1239
+ Slicing is ALWAYS on the values of the index, for ``[],ix,loc `` and ALWAYS positional with ``iloc ``
1240
+
1241
+ .. ipython :: python
1242
+
1243
+ sf[2 :4 ]
1244
+ sf.ix[2 :4 ]
1245
+ sf.loc[2 :4 ]
1246
+ sf.iloc[2 :4 ]
1247
+
1248
+ In float indexes, slicing using floats is allowed
1249
+
1250
+ .. ipython :: python
1251
+
1252
+ sf[2.1 :4.6 ]
1253
+ sf.loc[2.1 :4.6 ]
1254
+
1255
+ In non-float indexes, slicing using floats will raise a ``TypeError ``
1256
+
1257
+ .. code-block :: python
1258
+
1259
+ In [1 ]: Series(range (5 ))[3.5 ]
1260
+ TypeError : the label [3.5 ] is not a proper indexer for this index type (Int64Index)
1261
+
1262
+ In [1 ]: Series(range (5 ))[3.5 :4.5 ]
1263
+ TypeError : the slice start [3.5 ] is not a proper indexer for this index type (Int64Index)
1264
+
1265
+ Using a scalar float indexer will be deprecated in a future version, but is allowed for now.
1266
+
1267
+ .. code- block:: python
1268
+
1269
+ In [3 ]: Series(range (5 ))[3.0 ]
1270
+ Out[3 ]: 3
1271
+
1272
+ Here is a typical use- case for using this type of indexing. Imagine that you have a somewhat
1273
+ irregular timedelta- like indexing scheme, but the data is recorded as floats. This could for
1274
+ example be millisecond offsets.
1275
+
1276
+ .. ipython:: python
1277
+
1278
+ dfir = concat([DataFrame(randn(5 ,2 ),
1279
+ index = np.arange(5 ) * 250.0 ,
1280
+ columns = list (' AB' )),
1281
+ DataFrame(randn(6 ,2 ),
1282
+ index = np.arange(4 ,10 ) * 250.1 ,
1283
+ columns = list (' AB' ))])
1284
+ dfir
1285
+
1286
+ Selection operations then will always work on a value basis, for all selection operators.
1287
+
1288
+ .. ipython:: python
1289
+
1290
+ dfir[0 :1000.4 ]
1291
+ dfir.loc[0 :1001 ,' A' ]
1292
+ dfir.loc[1000.4 ]
1293
+
1294
+ You could then easily pick out the first 1 second (1000 ms) of data then.
1295
+
1296
+ .. ipython:: python
1297
+
1298
+ dfir[0 :1000 ]
1299
+
1300
+ Of course if you need integer based selection, then use `` iloc``
1301
+
1302
+ .. ipython:: python
1303
+
1304
+ dfir.iloc[0 :5 ]
1218
1305
1219
1306
.. _indexing.view_versus_copy:
1220
1307
0 commit comments