0

I have a .csv file with several thousands data points in the form:

Timestamp                  Variable
2016-01-01 00:00:00+00:00  3.6

I would like to import the data and create a 2D array with the timestamps in the first column and the variable values in the second. What's the most efficient way to do it?

0

2 Answers 2

1

I guess pandas is the library you need to manage your kind of data.

import pandas as pd
df = pd.read_csv('somefile.csv') 

res = df.values

You will need to look the documentation (https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html) on pandas to complete read_csv with the corrects arguments

Sign up to request clarification or add additional context in comments.

1 Comment

I'll try pandas then.
0

For the community's benefit, here is the instruction that solves my problem using pandas library. In my file, there are X and Y rows of metadata to skip respectively before and after the data of interest; your mileage may vary.

import pandas as pds
Y_raw= pds.read_csv('mydata.csv',
                  delimiter=',', header = None, engine = 'python',
                  skiprows = X, skipfooter = Y,
                  usecols = [0,1], names = ["TimeStamp", "Var"],  
                  parse_dates = [0], infer_datetime_format = True) ]

Then I can extract the Var and TimeStamp arrays with:

Y = Y_raw.iloc[:,1]
Z = y_raw.iloc[:,0]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.