I have initialised a dataframe like this:
df = pd.DataFrame(columns=["stockname","timestamp","price","volume"])
df.timestamp = pd.to_datetime(df.timestamp, format = "%Y-%m-%d %H:%M:%S:%f")
df.set_index(['stockname', 'timestamp'], inplace = True)
Now I get stream of data from somewhere but for the sake of program let me write it like this:
filehandle = open("datasource")
for line in filehandle:
line = line.rstrip()
data = line.split(",")
stockname = data[4]
price = float(data[3])
timestamp = pd.to_datetime(data[0], format = "%Y-%m-%d %H:%M:%S:%f")
volume = int(data[6])
df.loc[stockname, timestamp] = [price, volume]
filehandle.close()
print df
but this is giving error:
ValueError: cannot set using a multi-index selection indexer with a different length than the value
"datasource"?pd.read_csv. If you add the sample of text file I would show you how to do that.