【发布时间】:2021-03-24 06:05:34
【问题描述】:
我正在开发一个创建算法交易者的项目。但是,我想从我的数据框中删除周末,因为它破坏了 中所示的数据那个技术。它也不是数据框中的列。我是 python 新手,所以我不太确定,但我认为这是一个索引,因为当我通过 .index 函数时,它会显示日期和时间。如果这些是愚蠢的问题,我很抱歉,但我是 python 和 pandas 的新手。
这是我的代码:
#import all the libraries
import nsetools as ns
import pandas as pd
import numpy
import matplotlib.pyplot as plt
from datetime import datetime
import yfinance as yf
plt.style.use('fivethirtyeight')
a = input("Enter the ticker name you wish to apply strategy to")
ticker = yf.Ticker(a)
hist = ticker.history(period="1mo", interval="15m")
print(hist)
plt.figure(figsize=(12.5, 4.5))
plt.plot(hist['Close'], label=a)
plt.title('close price history')
plt.xlabel("13 Nov 2020 too 13 Dec 2020")
plt.ylabel("Close price")
plt.legend(loc='upper left')
plt.show()
编辑:根据用户的建议,我尝试将我的代码修改为此
refinedlist = hist[hist.index.dayofweek<5]plt.style.use('fivethirtyeight')
a = input("Enter the ticker name you wish to apply strategy to")
ticker = yf.Ticker(a)
hist = ticker.history(period="1mo", interval="15m")
refinedlist = hist[hist.index.dayofweek<5]
print (refinedlist)
【问题讨论】:
-
我完全按照上面所说的做了,添加了“refinedlist = hist[hist.index.dayofweek
标签: python pandas numpy dataframe matplotlib