I'm very new to the Python world and am working on a project. The project is to read from a CSV of user data and manipulate the data to create different reports on user health.
One of these reports is to figure out how many users have logged in within the last week. The 'last login' data was strings, but I converted to int. I appended the 'last login' into a separate list.
Some users have not logged in, therefore do not have a 'last login.' I replaced the empty indexes with 0, so no indexes were empty. I'm struggling with getting the timestamp into datetime (really any format: MM/DD/YYYY, HH:MM:SS). I keep getting an error:
ValueError: year is out of range
I've tried dividing by 1000, but still having issues. Any ideas?
Below is an example of the data I'm working with in my list.
[1544626810820, 1544647898313, 1543194669126, 1533042869622, 0, 1537968162473, 1538754659570, 1539198730173, 0, 0, 1543369525149, 0, 1535642246135, 1539806567884, 0, 1511208172787, 1542840156036, 1536345371483, 1515986690566, 0, 1516799608495, 0, 1536700256748, 1543374990449, 1544555559134, 1526915269686, 0, 1534523604072, 0, 1518555543753, 1540228140771, 1538586517246, 0, 1543840813753, 1534526715930, 0, 1540654014208, 0, 1543436093259, 1544641503675, 1538160074436, 1519667756523, 1539870078998, 0, 0, 1538748889751, 1522940503466, 1530518088966, 1544717763534, 0, 1544545768879, 1539803669673, 0, 1523901643633, 1538744148771, 1537983169153, 1538591931401, 0, 0, 0, 1529003670926, 1519228170054, 0, 0, 1506366784964, 1542450066936, 1541630106764, 1543425175040, 1544390856610, 1536854673722, 1542299240573, 1543424235993, 1536878439598, 1505248601850, 0, 0, 0, 0, 0, 1544621280620, 1508260711613, 1544565233469, 1543593841774, 0, 0, 0, 0, 0, 1538591968411, 0, 0, 1505420764995, 0, 0, 1543855009700, 0, 0, 0, 0, 0, 0, 1540406592563, 0, 1543011085517, 1544544779043, 0, 0, 1510618477771, 0, 0, 1542217475312]
Code used to get the error:
intLastLogin = [int(x) for x in lastLogin]
for row in intLastLogin:
dt = datetime.fromtimestamp(row).strftime('%Y-%m-%d %H:%M:%S')
print dt