gpt4 book ai didi

python - 字典中的特征数

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:58 25 4
gpt4 key购买 nike

我正在像这样从 pickle 文件加载数据集

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

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

'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.com', 'from_poi_to_this_person': 52}

现在,如何获得特征的数量?例如 (salary, to_messages, .... , from_poi_to_this_person)

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

谢谢

最佳答案

试试这个。

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

只有当您的所有 key 都在 data_dict 中时,这才有效具有相同数量的特征。

或简单地

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

<罢工>

关于python - 字典中的特征数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38050896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com