Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106886 > unrolled thread

python pandas convert strings to datetime problems

Started byDaiyue Weng <daiyueweng@gmail.com>
First post2016-04-11 17:08 +0100
Last post2016-04-11 17:08 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  python pandas convert strings to datetime problems Daiyue Weng <daiyueweng@gmail.com> - 2016-04-11 17:08 +0100

#106886 — python pandas convert strings to datetime problems

FromDaiyue Weng <daiyueweng@gmail.com>
Date2016-04-11 17:08 +0100
Subjectpython pandas convert strings to datetime problems
Message-ID<mailman.32.1460390927.15650.python-list@python.org>
Hi, I need to compare the years in a Series. The values in the Series is
like '1996', '2015', '2006-01-02' or '20130101' etc. The code I created is,

col_value_series = pd.to_datetime(col_value_series, infer_datetime_format=True)
min_year = col_value_series.min().year
max_year = col_value_series.max().year

current_year = datetime.date.today().year

res1 = min_year > 1970
res2 = max_year < current_year
return min_year > 1970 and max_year < current_year

the code is working fine on the values like '20030101' and '2006-01-02',
which are converted to datetime, i.e. '2003-01-01'. But it converted values
'1996' or '2015' to '1970-01-01 00:00:00.000001996' and '1970-01-01
00:00:00.000002015', which are completely wrong (meaning the years are all
1970 now). So how to resolve the issue.

thanks

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web