Suppose that we want to create a dataframe from a dictionary.
import pandas as pd,numpy as np #1) Form dataframe ix=pd.date_range('1/1/2015',periods=5,freq='D') df0=pd.DataFrame(np.random.normal(size=(len(ix),5)),index=ix) #2) Split dataframe into 2 dictionaries, based on sign d={'+':{},'-':{}} for loc in df0.index: d['+'][loc]=df0.loc[loc][df0.loc[loc]>=0] d['-'][loc]=df0.loc[loc][df0.loc[loc]<0] #3) Convert dictionary to dataframe print pd.DataFrame.from_dict(d['+'],orient='index')
This returns a dataframe of positive values, with NaN in place of the negative values. Now, it appears the exact same operation fails if we use "df.index.values" instead of "df.index".
d={'+':{},'-':{}} for loc in df0.index.values: # NOTE .values! d['+'][loc]=df0.loc[loc][df0.loc[loc]>=0] d['-'][loc]=df0.loc[loc][df0.loc[loc]<0] print pd.DataFrame.from_dict(d['+'],orient='index')
Now the outcome is a dataframe with all None. I think the problem is some inconsistency between pandas' datetime and numpy's datetime formats.
Pandas version 0.16.1, Numpy version 1.9.2. Thanks.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4