Time series from dataframe loses values

I have 2 dataframes, df1 and df2 of the same size, df1with a datecolumn and df2 with a float column. When I do the following:

series = pandas.Series(df2['float'], df1['date'])

The values on the time series are all NaN. I've checked both dataframes have data before doing it. What am I doing wrong?

Upvotes: 1

Views: 81

Answers (1)

EdChum
EdChum

Reputation: 394091

This looks like a bug to me:

In [29]:

df = pd.DataFrame({'date':[dt.datetime.now()]})
print(df)
df1 = pd.DataFrame({'float':[2.1145]})
df1
                        date
0 2015-02-23 11:23:03.550538
Out[29]:
    float
0  2.1145
In [30]:

pd.Series(df1['float'], df['date'])
Out[30]:
date
2015-02-23 11:23:03.550538   NaN
Name: float, dtype: float64

It works if you call the attribute .values:

In [31]:

pd.Series(df1['float'].values, df['date'])
Out[31]:
date
2015-02-23 11:23:03.550538    2.1145
dtype: float64

This looks like a generic bug:

In [34]:

df3 = pd.DataFrame({'int':[323]})
df3
Out[34]:
   int
0  323

The following combinations all fail:

In [39]:

pd.Series(df2['float'], df3['int'])
Out[39]:
int
323   NaN
Name: float, dtype: float64
In [40]:

pd.Series(df['date'], df2['float'])
Out[40]:
float
1.21554   NaT
Name: date, dtype: datetime64[ns]

In [41]:

pd.Series(df3['int'], df2['float'])
Out[41]:
float
1.21554   NaN
Name: int, dtype: float64

Upvotes: 3

Related Questions