Unix time format [SOLVED]
-
- Posts: 63
- Joined: 13 Sep 2016
- Has thanked: 30 times
- Been thanked: 8 times
Unix time format
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?
- Svetlana MultiCharts
- Posts: 645
- Joined: 19 Oct 2017
- Has thanked: 3 times
- Been thanked: 163 times
Re: Unix time format
Hello, TraderWalrus,
It will be required to create two separate columns for date and time in order to import/map the file.
It will be required to create two separate columns for date and time in order to import/map the file.
-
- Posts: 63
- Joined: 13 Sep 2016
- Has thanked: 30 times
- Been thanked: 8 times
Re: Unix time format [SOLVED]
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)