ValueError Traceback (most recent call last) Cell In[4], line 220 218 start_time = datetime(2022, 5, 1) 219 end_time = datetime(2023, 4, 30) --> 220 df = get_kline(htsc_code=total_codes, time=[start_time, end_time], 221 frequency="daily", fq="pre") 223 # 回测时间,在本例中为2022.8.30-2022.9.8 224 backtest_start_time = datetime(2022, 8, 30) File ~\anaconda3\envs\demo_env\lib\site-packages\insight_python\com\insight\query.py:34, in get_kline(htsc_code, time, frequency, fq) 25 def get_kline(htsc_code=None, time=None, frequency='daily', fq="pre"): 26 ''' 27 :param htsc_code: 华泰证券代码,支持多个code查询,列表类型 28 :param time: 时间范围,list类型,开始结束时间为datetime (...) 31 :return:pandas.DataFrame 32 ''' ---> 34 if htsc_code: 35 if not isinstance(htsc_code, str) and not isinstance(htsc_code, list): 36 return "htsc_code format is not str or list" File ~\anaconda3\envs\demo_env\lib\site-packages\pandas\core\generic.py:1527, in NDFrame.__nonzero__(self) 1525 @final 1526 def __nonzero__(self) -> NoReturn: -> 1527 raise ValueError( 1528 f"The truth value of a {type(self).__name__} is ambiguous. " 1529 "Use a.empty, a.bool(), a.item(), a.any() or a.all()." 1530 ) ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
时间: 2023-06-17 17:07:25 浏览: 166
Python解析json之ValueError: Expecting property name enclosed in double quotes: line 1 column 2(char 1)
这个错误提示的含义是DataFrame的真值是不确定的,需要使用a.empty、a.bool()、a.item()、a.any()或a.all()等方法来判断。看起来是在判断htsc_code是否存在时出现问题。建议检查一下传入的htsc_code是否正确并且是否为DataFrame类型。另外,可能还需要检查一下get_kline()函数的实现是否存在其他问题。
阅读全文