0

I have a dataframe that looks like in the picture in the link (first 5 and last 5 observations shown).

current dataframe structure

I would like to manipulate this dataframe by removing the symbol column and instead having the symbol/settle value as multiple columns. So the output should look like the picture in the link below (the dataframe would have 70+ symbol columns but just showing two symbols as an example) and produce a NaN if there's no corresponding settle price for a symbol for a certain date. The dates to be used are those of the symbol ES (not shown below).

desired dataframe structure

#Import libraries and read the CSV file
import numpy as np
import pandas as pd

df=pd.read_csv('Futures Correlation Matrix.csv', index_col='DATE', usecols=['DATE', 'SYMBOL', 'SETTLE'])

#Convert index series to datetime
df.index=pd.to_datetime(df.index)

#Sort the dataframe by index and symbol
df=df.sort_values(by = ['SYMBOL', 'DATE'], ascending = [True, True])

PS: This is my first post on stackoverflow so I apologize beforehand if the question isn't clear enough.

Mister
  • 1
  • 1

0 Answers0