词典中的功能数

编程入门 行业动态 更新时间:2024-10-27 00:35:13
本文介绍了词典中的功能数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在从像这样的泡菜文件中加载数据集

I am working on loading a dataset from a pickle file like this

""" Load the dictionary containing the dataset """ with open("final_project_dataset.pkl", "r") as data_file: data_dict = pickle.load(data_file)

它可以正常工作并正确加载数据.这是一行的示例:

It works fine and loads the data correctly. This is an example of one row:

'GLISAN JR BEN F': {'salary': 274975, 'to_messages': 873, 'deferral_payments': 'NaN', 'total_payments': 1272284, 'exercised_stock_options': 384728, 'bonus': 600000, 'restricted_stock': 393818, 'shared_receipt_with_poi': 874, 'restricted_stock_deferred': 'NaN', 'total_stock_value': 778546, 'expenses': 125978, 'loan_advances': 'NaN', 'from_messages': 16, 'other': 200308, 'from_this_person_to_poi': 6, 'poi': True, 'director_fees': 'NaN', 'deferred_income': 'NaN', 'long_term_incentive': 71023, 'email_address': 'ben.glisan@enron', 'from_poi_to_this_person': 52}

现在,如何获得功能数量?例如(salary, to_messages, .... , from_poi_to_this_person)吗?

Now, how can get the number of features? e.g (salary, to_messages, .... , from_poi_to_this_person) ?

我通过打印整个数据集(print data_dict)得到了这一行,这是结果之一.我想知道整个数据集中有多少个特征,而没有在字典中指定键.

I got this row by printing my whole dataset (print data_dict) and this is one of the results. I want to know how many features are there is general i.e. in the whole dataset without specifying a key in the dictionary.

谢谢

推荐答案

尝试一下.

no_of_features = len(data_dict[data_dict.keys()[0]])

仅当data_dict中的所有键都具有相同数量的功能时,此功能才起作用.

This will work only if all your keys in data_dict have same number of features.

或简单地

or simply

no_of_features = len(data_dict['GLISAN JR BEN F'])

更多推荐

词典中的功能数

本文发布于:2023-11-15 16:50:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词典   功能

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!