[Solved] Try to plot finance data with datetime but met error TypeError: string indices must be integers, not str


The following could be used to plot your data. The main point is that you need to specify the (rather unusual) format of the datetimes ("%Y/%m/%d/%H/%M"), such that it can be converted to a datetime object.

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("data/minuteData.csv")
df["minute"] = pd.to_datetime(df["minute"], format="%Y/%m/%d/%H/%M")

plt.plot(df["minute"],df["spreadprice"], label="spreadprice" )
plt.plot(df["minute"],df["bollup"], label="bollup" )
plt.legend()
plt.show()

enter image description here

0

solved Try to plot finance data with datetime but met error TypeError: string indices must be integers, not str