1

Speed.csv:

date, Speed
1612852881000000000,10000
1612852882000000000,10000
1612852883000000000,10000
1612852884000000000,10000
1612852885000000000,10000
1612852886000000000,10000
1612852887000000000,10000
1612852888000000000,10000
1612852889000000000,10000
1612852890000000000,10000
1612852891000000000,10000

my code:
import time
import _csv
import pandas as pd

def convert_from_unix_stamp(raw):
  return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(raw) / 1000))

out=open("Speed.csv","r")
data=_csv.reader(out)

data=[(convert_from_unix_stamp(row[0]),row[1]) for row in data]
out.close()

a = pd.DataFrame(data)
print(a)

The Error:

  File "linux_time_stamp_conversion_csv.py", line 20, in <module>
    data=[(convert_from_unix_stamp(row[0]),row[1]) for row in data]
  File "linux_time_stamp_conversion_csv.py", line 20, in <listcomp>
    data=[(convert_from_unix_stamp(row[0]),row[1]) for row in data]
  File "linux_time_stamp_conversion_csv.py", line 15, in convert_from_unix_stamp
    return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(raw) / 1000000))
ValueError: invalid literal for int() with base 10: 'date'


I know that the unix timestamp is too big for an intiger.

How exactly can I change that? Or rather how can I change the encoding?

Passi
  • 127
  • 1
  • 13
  • 2
    The linked duplicate doesn't solve pasted error message at all. OP just forgot to skip the header in the .csv file. I.e. the word "date" is not an int. To solve, use `data = pd.read_csv("Speed.csv", header=1)` instead of `data = _csv.reader(out)`. – Joooeey Jul 15 '21 at 15:18

0 Answers0