I am trying to iterate over a single column 'YEAR'in a dataframe which has objects that appear like "1998" and "2006-2008". For the second example, I would like to convert those to an integer average value between the two like "2007". How should I go about doing this?
Asked
Active
Viewed 248 times
0
-
And for something like `2006-2007`, what would you want? Or does that never happen? – zondo Aug 14 '17 at 21:38
-
Any code you have written? – Hariom Singh Aug 14 '17 at 21:39
-
I would prefer to round to the nearest integer in the case of a decimal. – B R Aug 14 '17 at 21:44
-
I am trying to implement this code I found on a different post by @petermortenson here [basic links](https://stackoverflow.com/questions/1841565/valueerror-invalid-literal-for-int-with-base-10) `h = open(fname) for line in h: if line.strip(): [int(next(h).strip()) for _ in range(4)] # list of integers` – B R Aug 14 '17 at 21:52
1 Answers
0
import arrow
def date_to_int(value):
time_zone_diff = 8 * 60 * 60
return arrow.get(value).timestamp - time_zone_diff

yongyu
- 97
- 1
- 8