简体   繁体   English

从Python 2.7切换到3.7错误:“ TypeError:'generator'对象不可下标”

[英]Switching from Python 2.7 to 3.7 error: “TypeError: 'generator' object is not subscriptable”

I am upgrading my Python environment and this code that used to run in Python versions 2.7 and 3.6 now is displaying this error message: 我正在升级我的Python环境,以前在python版本2.7和3.6中运行的此代码现在显示以下错误消息:

TypeError: 'generator' object is not subscriptable TypeError:“发电机”对象不可下标

Precisely on this instruction: np.array(dataset['data']) 正好在此指令上:np.array(dataset ['data'])

where dataset is an variable containing arff file loaded... 其中数据集是包含加载的arff文件的变量...

Trying to dig I undeerstood that is something about iterator... but with the samples I tried I could not fix... Any help is welcome! 尝试挖掘我的想法,这与迭代器有关...但是对于示例,我尝试无法解决...欢迎任何帮助!

dataset = arff.load(open('datasets/temporal_extract_14_3_2.first_1_hours.arff',  'r'))
data = np.array(dataset['data'])
df = pd.DataFrame(data)
df.head()

摆脱打开的文件处理程序。

dataset = arff.load('datasets/temporal_extract_14_3_2.first_1_hours.arff')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM