python - Merging dataframe rows that have a offset (generated the same day but bearing a different timestamp) -


i'm trying merge several dataframes, in each frame data such

timestamp   cap 0   1387118554000   3488670 1   1387243928000   1619159 2   1387336027000   2191987 3   1387435314000   4299421 4   1387539459000   9866232 

each value represents daily generated data, each value not generated @ exact same millisecond timestamps not merge. need way convert timestamp year, month , day components. able merge data sets (unless there way solve such issue).

you can try to_datetime:

print pd.to_datetime(df['timestamp'], unit='ms') 0   2013-12-15 14:42:34 1   2013-12-17 01:32:08 2   2013-12-18 03:07:07 3   2013-12-19 06:41:54 4   2013-12-20 11:37:39 name: timestamp, dtype: datetime64[ns]  df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms') print df             timestamp      cap 0 2013-12-15 14:42:34  3488670 1 2013-12-17 01:32:08  1619159 2 2013-12-18 03:07:07  2191987 3 2013-12-19 06:41:54  4299421 4 2013-12-20 11:37:39  9866232 

then can use dt.date:

df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms').dt.date print df     timestamp      cap 0  2013-12-15  3488670 1  2013-12-17  1619159 2  2013-12-18  2191987 3  2013-12-19  4299421 4  2013-12-20  9866232 

or dt.strftime:

df['timestamp1'] = pd.to_datetime(df['timestamp'], unit='ms').dt.strftime('%y-%m-%d') print df int64index([0, 1, 2, 3, 4], dtype='int64')        timestamp      cap  timestamp1 0  1387118554000  3488670  2013-12-15 1  1387243928000  1619159  2013-12-17 2  1387336027000  2191987  2013-12-18 3  1387435314000  4299421  2013-12-19 4  1387539459000  9866232  2013-12-20 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -