pandas之Dataframe转成dict+过滤+index去重

转成字典
a = ['key1', 'key2', 'key3']
b = ['1', '2', '3']
data = pd.DataFrame(zip(a, b), columns=['project', 'attribute'])
print(data)
dict_country = data.set_index('project').T.to_dict()
dict_country = data.set_index('project').T.to_dict('list')
print(dict_country)

过滤

ret_df = df.loc[df['列名'] == '列值']

索引去重
print(ret_df[ret_df.index.duplicated()]) 

 
posted @ 2019-04-18 16:53  zxpo  阅读(2584)  评论(0编辑  收藏  举报