Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
fill_value kwarg for unstack #9746
Comments
|
You can do this by specifying the
|
jreback
closed this
Mar 29, 2015
jreback
added Missing-data API Design Usage Question
labels
Mar 29, 2015
|
There may be some merit to this being allowed directly, even if the functionality can be accomplished with a series of operations. For instance, when trying to limit memory usage on a big dataset, perhaps it would be preferable to keep the data as In [15]: idx = np.array([0, 0, 1], dtype=np.int32)
In [16]: idx2 = np.array([0, 1, 0], dtype=np.int8)
In [17]: value = np.array([0, 1, 2], dtype=np.int8)
In [18]: df = pd.DataFrame({'idx':idx, 'idx2':idx2, 'value':value})
In [19]: df.dtypes
Out[19]:
idx int32
idx2 int8
value int8
dtype: object
In [20]: df.set_index(['idx', 'idx2']).unstack().dtypes
Out[20]:
idx2
value 0 float64
1 float64
dtype: objectAfter the unstack my data table is suddenly much larger than necessary. Also, from looking at the code this would be fairly trivial to implement, without much impact on existing code. |
|
@amcpherson ok, if you can find a reasonable way to do this w/o affecting perf then would be ok to have a |
amcpherson commentedMar 29, 2015
Currently:
If I want to fill with -1, i need to
fillnaand thenastypeback toint. Ideally: