I am learning python for beginners. I would like to convert column values from unicode time ('1383260400000') to timestamp (1970-01-01 00:00:01enter code here
). I have read and tried the following but its giving me an error.
ti=datetime.datetime.utcfromtimestamp(int(arr[1]).strftime('%Y-%m-%d %H:%M:%S');
Its saying invalid syntax. I read and tried a few other stuffs but I can not come right.. Any suggestion?
And another one, in the same file I have some empty cells that I would like to replace with 0, I tried this too and its giving me invalid syntax:
smsin=arr[3];
if arr[3]='' :
smsin='0';
Please help. Thank you alot.
You seem to have forgotten a closing bracket after
(arr[1])
.To replace empty strings with '0's in your list you could do:
Note that the latter only works correctly since the empty string
''
is the only string with a truth value ofFalse
. If you had other data types withinarr
(e.g.0
,0L
,0.0
,()
,[]
, ...) and only wanted to replace the empty strings you would have to do:More efficient yet would be to modify
arr
in place instead of recreating the whole list.But if that is not an issue (e.g. your list is not too large) I would prefer the former (more readable) way.
Also you don't need to put
;
s at the end of your code lines as Python does not require them to terminate statements. They can be used to delimit statements if you wish to put multiple statements on the same line but that is not the case in your code.