下面lock
行(接近结尾处)的错误:
def change_to_date(string):
seq = (string[:2],string[2:5],string[5:])
return '-'.join(seq)
pt['DATE'] = pt['DATE'].apply(change_to_date)
错误是:
option.py
这是文件ws.cell(row=i,column=j).value=c
:
raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert [Date
2014-12-01 8555.9
Name: Close, dtype: float64] to Excel
答案 0 :(得分:0)
我没有使用nsepy.derivatives
或openpyxl
,所以我无法验证或确认。但是错误会指出您的大部分情况:
在Excel中无法完全/正确地理解在get_expiry_date
行中从expiry=get_expiry_date(year=xyear,month=xmonth)
获得的正确的Python datetime
对象。
您可以在openpyxl
代码中更深入地了解如何管理日期,但是除非加以限制,只需将datetime
对象转换为所需格式的字符串,然后再将其推出Excel。 / p>
在for c in data:
之后,您可以添加:
if isinstance(c, datetime.datetime):
d = d.strftime("%Y-%m-%d")
这会将d
转换为类似"2018-06-30"
(年,月,日)格式的字符串。您可以将其更改为您喜欢的任何格式...我更喜欢这里给出的亚洲风格,因为它完全不含糊。
PS。我认真编辑了您的问题,使其更易于管理。问题越容易阅读/理解,您得到的答复就会越多/越好。