毕业论文中用于计算联合国会员国间在联合国大会上的投票一致性(IVC)

import pandas as pd
import sqlite3
import networkx as nx
import time
import numpy as np
def gen_dict(sql):#建立投票数据字典
votedict={}
votedict['all']={}
for c in cntylist:
votedict['all'][c]={}
votedict['all'][c]['yes']=[]
votedict['all'][c]['noyes']=[]
votedict['all'][c]['qq']=[]
votedict['all'][c]['no']=[]
votedict['all'][c]['all']=[]
for y in [1992,2001,2010]:
votedict[y]={}
for c in cntylist:
votedict[y][c]={}
votedict[y][c]['yes']=[]
votedict[y][c]['noyes']=[]
votedict[y][c]['qq']=[]
votedict[y][c]['no']=[]
votedict[y][c]['all']=[]
for c in cntylist:
c1=c
r1sql='select rcid, Country, vote, year from data where vote<4 and Country= \'%s\'' % c1 + sql
rec1=pd.read_sql(r1sql ,conn)
yeslist=rec1[rec1['vote']==1]['rcid'].tolist()
noyeslist=rec1[(rec1['vote']==2)|(rec1['vote']==3)]['rcid'].tolist()
nolist=rec1[rec1['vote']==3]['rcid'].tolist()
qqlist=rec1[rec1['vote']==2]['rcid'].tolist()
votedict['all'][c]['yes']=yeslist
votedict['all'][c]['noyes']=noyeslist
votedict['all'][c]['qq']=qqlist
votedict['all'][c]['no']=nolist
votedict['all'][c]['all']=rec1['rcid'].tolist()
for y in [1992,2001,2010]:
for c in cntylist:
c1=c
yearsql='and year>= %d and year< %d'%(y,y+8)
r1sql='select rcid, Country, vote, year from data where vote<4 and Country= \'%s\'' % c1+yearsql+sql
rec1=pd.read_sql(r1sql ,conn)
yeslist=rec1[rec1['vote']==1]['rcid'].tolist()
noyeslist=rec1[(rec1['vote']==2)|(rec1['vote']==3)]['rcid'].tolist()
nolist=rec1[rec1['vote']==3]['rcid'].tolist()
qqlist=rec1[rec1['vote']==2]['rcid'].tolist()
votedict[y][c]['yes']=yeslist
votedict[y][c]['noyes']=noyeslist
votedict[y][c]['qq']=qqlist
votedict[y][c]['no']=nolist
votedict[y][c]['all']=rec1['rcid'].tolist()
print(sql,y,'生成该年份数据')
print(sql,'数据字典已经生成')
return votedict
def ivc_gen_new(thedict,c1,c2):#基于字典计算两国间IVC
c1yes= thedict[c1]['yes']
c1no= thedict[c1]['no']
c1noyes=thedict[c1]['noyes']
c1qq=thedict[c1]['qq']
c2yes= thedict[c2]['yes']
c2no=thedict[c2]['no']
c2noyes=thedict[c2]['noyes']
c2qq=thedict[c2]['qq']
c1all=thedict[c1]['all']
c2all=thedict[c2]['all']
flist=[x for x in c1yes if x in c2yes]+[x for x in c1qq if x in c2qq]+[x for x in c1no if x in c2no]
glist=[x for x in c1qq if x in c2yes+c2no]+[x for x in c2qq if x in c1yes+c1no]
f=len(set(flist))
g=len(set(glist))
t=len(set([c for c in c1all if c in c2all]))
try:
ivc=(f+0.5*g)/t
except:
ivc=0
return ivc

IVC方法参考

Turner J. Party and constituency: Pressures on congress[M]. Baltimore: The Johns Hopkins Press, 1952.

最新文章

  1. C# 禁止修改已装箱了的值类型的字段值,但是可以通过接口的方式实现
  2. spring boot 跨域访问处理
  3. lightoj 1074 spfa判断负环
  4. 使用python的subprocess启动windows程序提示WindowsError: [Error 6] The handle is invalid
  5. Openwrt flash 空间不足的临时解决方法
  6. 工作中遇到的问题--eclipse没有方法提示
  7. 数往知来SQL SERVER 视图 触发器 &lt;九&gt;
  8. Fragment实现底部选项卡切换效果
  9. 201521123062《Java程序设计》第9周学习总结
  10. kali linux安装搜狗输入法的方法
  11. 关于MVC的特性(AuthorizeAttribute)的一些理解
  12. Game Engine Architecture 11
  13. 软件包管理之rpm与yum
  14. 使用django实现自定义用户认证
  15. VC调试小结
  16. SDN2017 第四次实验作业
  17. CSS 中 calc() 函数用法
  18. python之列表操作
  19. 如何做一个像btbook.net这样的搜片神器?
  20. [状态机]嵌入式设计模式:有限状态自动机的C语言实现

热门文章

  1. python图片转base64、base64转图片
  2. 调度器46—tick模式
  3. 3516A调试
  4. MQTT QoS 0, 1, 2 介绍
  5. thinkphp6+composer+无集成工具 配置php项目环境
  6. Windows系统的显示器校正
  7. html的table多级表头表格的代码
  8. 【python基础教程】-10.开箱即用(模块的工作原理,获悉模块的功能以及常用模块)
  9. jmeter分布式压测配置
  10. kotlin inline的缺点