У меня есть фрейм данных с финансовыми данными (Дата, Открыть, Закрыть, Низкий, Высокий).
Я хочу построить график зависимости даты от одного столбца (например, Открыть).Когда я конвертирую столбец «Дата» в дату, график отображается неправильно.Почему это могло произойти?
import pandas as pd
import matplotlib.pyplot as plt
def plot_one_data(df, column, title= "No Title", color = "black"):
df.plot(x="Date", y=column, title=title)
#show plot
filename= title+ ".png"
plt.savefig(filename)
#Load in the csv files
df = pd.read_csv('data/df.csv')
print(df.head())
plot_one_data(df, "Open", "Before Converting to Date - good but no dates on x axis")
df['Date'] = pd.to_datetime(df["Date"])
print(df.head())
plot_one_data(df, "Open", "After Converting to Date - bad!")
Вывод текста:
Date Open ... Adj Close Volume
0 14-08-06 1266.670044 ... 1268.209961 2118020000
1 15-08-06 1268.189941 ... 1285.579956 2334100000
2 16-08-06 1285.270020 ... 1295.430054 2554570000
3 17-08-06 1295.369995 ... 1297.479980 2458340000
4 18-08-06 1297.479980 ... 1302.300049 2033910000
[5 rows x 7 columns]
Date Open ... Adj Close Volume
0 2006-08-14 1266.670044 ... 1268.209961 2118020000
1 2006-08-15 1268.189941 ... 1285.579956 2334100000
2 2006-08-16 1285.270020 ... 1295.430054 2554570000
3 2006-08-17 1295.369995 ... 1297.479980 2458340000
4 2006-08-18 1297.479980 ... 1302.300049 2033910000

