0

I have the following excel file and the time stamp in the format

20180821_2330

1) for a lot of days. How would I format it as standard time so that I can plot it versus the other sensor values ?

2) I would like to have a big plot with for example sensor 1 reading against all the days, is that possible ?

https://www.mediafire.com/file/m36ha4777d6epvd/median_data.xlsx/file

ChaosPredictor
  • 3,777
  • 1
  • 36
  • 46
andre
  • 731
  • 2
  • 13
  • 27
  • Possible duplicate of [Parsing time string in Python](https://stackoverflow.com/questions/10494312/parsing-time-string-in-python) – Marcin Orlowski Oct 25 '18 at 10:21

1 Answers1

0

is this something you are looking for? I improvised and created 'n' column which could represent your 'timestamp' as the data frame. Basically, what I think you should do, is to apply another function - let's call it 'apply_fun' on your column which stores 'timestamps' a function which takes each element and transforms it into strptime() format.

import datetime
import pandas as pd

n = {'timestamp':['20180822_2330', '20180821_2334', '20180821_2334', '20180821_2330']}
data_series = pd.DataFrame(n)

def format_dates(n):
    x = n.find('_')
    y = datetime.datetime.strptime(n[:x]+n[x+1:], '%Y%m%d%H%M')
    return y


def apply_fun(dataset):
    dataset['timestamp2'] = dataset['timestamp'].apply(format_dates)
    return dataset

print(apply_fun(data_series))

When it comes to 2nd point, I am not able to reach the site due to McAffe agent at work, which does not allow to open it. Once you have 1st, you can ask for 2nd separately.

krakowi
  • 583
  • 5
  • 17
  • Thanks. you got the idea. but n is a dataframe how can I replace and format all that column with your code ? – andre Oct 25 '18 at 11:12
  • here is the link for the data https://www.dropbox.com/s/bzphpa6vri5xkbg/median_data.xlsx?dl=0 – andre Oct 25 '18 at 11:14
  • Check out my last update, this might be somehow helpful. This approach does not remove the original column (just in case you'd like to have it). But you could always replace it, just change 'timestamp2' into 'timestamp'. – krakowi Oct 25 '18 at 12:10