I have the following dataframe df where there are 3 columns: Date, value and topic. I want to create a new dataframe df1 where the topic is the column and is indexed by day, and each topic has its own value per day. My problem is that I don't know how to match the value to the topic per day. Any help would be appreciated.
import numpy as np
import pandas as pd
import random
rng = pd.date_range('2015-02-24', periods=50, freq='H')
TOPIC=np.random.choice(5, len(rng), replace=True)
df = pd.DataFrame({ 'Date': rng, 'Val' : np.random.randn(len(rng)),'Topic':TOPIC})
columns=df.Topic.unique()
df1=pd.DataFrame(columns=columns)
df1['Date']=df['Date']
df1.set_index('Date',inplace=True)
df1=df1.resample('D').ffill()
df1