这是我的Transaction班级:
class Transaction(object):
def __init__(self, company, num, price, date, is_buy):
self.company = company
self.num = num
self.price = price
self.date = datetime.strptime(date, "%Y-%m-%d")
self.is_buy = is_buy
Run Code Online (Sandbox Code Playgroud)
当我试图运行该date功能时:
tr = Transaction('AAPL', 600, '2013-10-25')
print tr.date
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
self.date = datetime.strptime(self.d, "%Y-%m-%d")
AttributeError: 'module' object has no attribute 'strptime'
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
嗨我想在matplotlib中将日期列表转换为字符串到x轴,我似乎无法让它出来正确.
dates = ['2014-05-06', '2014-05-07', '2014-05-08', '2014-05-09', '2014-05-10', '2014-05-11', '2014-05-12', '2014-05-13']
import matplotlib
from matplotlib import pyplot
from matplotlib import dates
converted_dates = matplotlib.dates.datestr2num(dates)
x_axis = (converted_dates)
y_axis = range(0,8)
pyplot.plot( x_axis, y_axis, '-' )
pyplot.show()
Run Code Online (Sandbox Code Playgroud)
这会在图表的x轴上带回1 2 3 4 5 6 7,我错过了什么.我希望这能显示2014-05-06等