Skip to content
All library documents

Importing Dated Asset Return Series into Python with Pandas

Article Quant Q&A · Author: hedgebet340

Summary

The document asks how to load many years of daily returns for multiple assets from a spreadsheet or CSV into Python, and how to retain the associated dates. The response recommends Pandas as a straightforward tool for reading a CSV into a data structure that keeps the columns together. In this setup, each asset can remain a separate column, while dates can be represented as a column or index rather than being lost when observations are numbered sequentially.

The exchange is a brief starting point rather than a full data-management guide. It supplies no comparison of storage formats, validation steps, handling for missing observations, or advice on aligning calendars across asset classes. It also does not discuss performance for long histories or demonstrate processing the resulting data. Its practical contribution is the basic recommendation to use a tabular data library for importing returns, with dates and asset series retained together for later analysis.

Key ideas

  • Pandas can read CSV files containing return data into a tabular structure.
  • Keep each asset’s return series associated with its observation date.
  • A dated table can be easier to work with than separate lists indexed only by row number.
  • The exchange gives a basic import suggestion rather than a complete data workflow.

Tags

Full text
# importing columns of returns data into python from excel/csv


# importing columns of returns data into python from excel/csv












I'm fairly new to the quant finance space, and I was hoping to get some guidance. Say I have a csv/excel file with columns of daily returns data for various asset classes or securities (one column per asset). I want to be able to import these returns data into Python, probably as lists/arrays.

If there are many days worth of data (say 10 years worth), what's the best way to go about this, import-wise and data structure-wise? Any packages that could help?

A minor note, I was considering using dictionaries so I could still retain the date/day, whereas if I just use lists I would just index it as 1,2,3,4...n_th day.

Thanks!

## Answer by CharlesM (score 1)

https://quant.stackexchange.com/a/18151

True this is a stackoverflow question but have you tried the fool around with the package `Pandas`? You can do in Python

`import pandas as pd`

`data = pd.read_csv('filepath/file.csv')`

That's the easiest way.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.