i have dataframe consisting of 5 decreasing series (290 rows each) values comprised between 0 , 1.
the data looks that:
b c d e 0.60 0.998494 1.0 1.0 1.0 1.0 0.65 0.997792 1.0 1.0 1.0 1.0 0.70 0.996860 1.0 1.0 1.0 1.0 0.75 0.995359 1.0 1.0 1.0 1.0 0.80 0.992870 1.0 1.0 1.0 1.0
i want reindex dataframe have 0.01 increments between each row. i've tried pd.dataframe.reindex
no avail: returns dataframe of values np.nan
import pandas pd df = pd.read_csv('http://pastebin.com/raw/yehdk2gq', index_col=0) print df.reindex(np.arange(0.6, 3.5, 0.025)).head()
which returns 2 valid rows, , converts 288 others nan
:
b c d e 0.600 0.998494 1.0 1.0 1.0 1.0 0.625 nan nan nan nan nan 0.650 0.997792 1.0 1.0 1.0 1.0 0.675 nan nan nan nan nan 0.700 nan nan nan nan nan ##this row existed before reindexing
pandas can't match new index intial values, although there doesn't seem rounding issues (the initial index has no more 2 decimals).
this seems somehow related data following works intended:
df = pd.dataframe(np.random.randn(10,3), columns=['a', 'b', 'c'])\ .reindex(np.arange(1, 10, 0.5)) print df.head()
which gives:
b c 1.0 0.206539 0.346656 2.578709 1.5 nan nan nan 2.0 1.164226 2.693394 1.183696 2.5 nan nan nan 3.0 -0.532072 -1.044149 0.818853
thanks help!
this because precision of numpy.
in [31]: np.arange(0.6, 3.5, 0.025).tolist()[0:10] out[31]: [0.6, 0.625, 0.65, 0.675, 0.7000000000000001, 0.7250000000000001, 0.7500000000000001, 0.7750000000000001, 0.8000000000000002, 0.8250000000000002]
Comments
Post a Comment