Skip to content Skip to sidebar Skip to footer

Pandas Series TypeError And ValueError When Using Datetime

The code below works just fine (as expected): import dateutil from pandas import Series timestamp = dateutil.parser.parse('2014-09-30 00:00:00') ser = Series() ser['no_num'] = 'st

Solution 1:

Series are single-dtyped. So putting different dtypes in a single container while possible is not recommended. The series will change dtype to accomodate the dtypes as you add them (which FYI is not efficient at all, better to pass in a list in the first place).

Your example fails because the Series is already a float dtype and cannot hold a Timestamp which is an object.

You can do this if you really want.

In [42]: ser = Series([5.0,timestamp],['no_num','time'])

In [43]: ser
Out[43]: 
no_num                      5
time      2014-09-30 00:00:00
dtype: object

Post a Comment for "Pandas Series TypeError And ValueError When Using Datetime"