Unix time format  [SOLVED]

Questions about MultiCharts and user contributed studies.
TraderWalrus
Posts: 63
Joined: 13 Sep 2016
Has thanked: 30 times
Been thanked: 8 times

Unix time format

Postby TraderWalrus » 12 Feb 2018

I want to import data with a timestamp of a single column, in Unix time format. Is there any way to do that from QuoteManager or must I first convert it to two columns of date and time?

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: Unix time format

Postby Svetlana MultiCharts » 14 Feb 2018

Hello, TraderWalrus,

It will be required to create two separate columns for date and time in order to import/map the file.

TraderWalrus
Posts: 63
Joined: 13 Sep 2016
Has thanked: 30 times
Been thanked: 8 times

Re: Unix time format  [SOLVED]

Postby TraderWalrus » 15 Feb 2018

OK, in case anyone has the same issue in the future, here's how I did it in python:

Code: Select all

import pandas as p

def splitUnixTime(inputFileName="input.csv",outputFileName="output.csv",nrows=None):

# read CSV
df = p.read_csv(inputFileName,usecols=["Timestamp","Open","High","Low","Close"],nrows = nrows)

# set timestamp as index
df.set_index(["Timestamp"],inplace=True)

# convert unix timestamp to date and time
ts = p.to_datetime(df.index, unit='s')

# add the converted columns to the dataframe and export CSV
df.assign(Date=ts.date, Time=ts.time).to_csv(outputFileName,index=False)


Return to “MultiCharts”