毕业论文中用于计算联合国会员国间在联合国大会上的投票一致性(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.

python投票一致性指数(IVC)实现代码的更多相关文章

  1. Python实现各种排序算法的代码示例总结

    Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示 ...

  2. 【原创】用Python爬取LeetCode的AC代码到Github

    在leetCode写了105道题高调膜科,考虑搬迁到自己的GitHub上,做成一个解题题库,面试的时候也可以秀一个 但是!但是! leetCode在线IDE的功能不要太舒服,我直接线上A了不少题,本地 ...

  3. Python绘制3d螺旋曲线图实例代码

    Axes3D.plot(xs, ys, *args, **kwargs) 绘制2D或3D数据 参数 描述 xs, ys X轴,Y轴坐标定点 zs Z值,每一个点的值都是1 zdir 绘制2D集合时使用 ...

  4. Python爬虫 - 爬取百度html代码前200行

    Python爬虫 - 爬取百度html代码前200行 - 改进版,  增加了对字符串的.strip()处理 源代码如下: # 改进版, 增加了 .strip()方法的使用 # coding=utf-8 ...

  5. 软件测试自动化…python学习到什么程度?代码好不好学!

    软件测试自动化…python学习到什么程度?代码好不好学! 如下:

  6. python 类继承演示范例的代码

    把做工程过程重要的代码片段备份一次,下面的资料是关于python 类继承演示范例的代码. # a simple example of a class inheritance # tested with ...

  7. 震惊!!!python可以用中文来写代码

    python可以用中文来写代码 说明: 偶尔间试了一下,python可以用中文来写代码,除了一些python内置函数,和运算符不能用中文外,其它的比如新定义的类名.函数名.变量名,甚至是函数间传的参数 ...

  8. python爬取网页的通用代码框架

    python爬取网页的通用代码框架: def getHTMLText(url):#参数code缺省值为‘utf-8’(编码方式) try: r=requests.get(url,timeout=30) ...

  9. Python 工匠:编写条件分支代码的技巧

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由鹅厂优文发表于云+社区专栏 作者:朱雷 | 腾讯IEG高级工程师 『Python 工匠』是什么? 我一直觉得编程某种意义是一门『手艺』 ...

  10. Python解决八皇后问题的代码【解读】

    八皇后问题 来自于西方象棋(现在叫 国际象棋,英文chess),详情可见百度百科. 在西方象棋中,有一种叫做皇后的棋子,在棋盘上,如果双方的皇后在同一行.同一列或同一斜线上,就会互相攻击. 八皇后问题 ...

随机推荐

  1. 遇到bug怎么分析,这篇文章值得一看

    博主总结的非常到位:https://mp.weixin.qq.com/s/UpaLWjix2tnfTqybx9dmoQ 为什么定位问题如此重要? 可以明确一个问题是不是真的"bug" ...

  2. 关于在ItelliJ IDEA社区版找不到Spring Initializr

    搜了好几个版本都没找到,太难顶了... 打开「ItelliJ IDEA社区版」→「Configure」→「Plugins」→搜索框搜索「Spring Assistant」→「Install」 还要配置 ...

  3. shell语句记录

    sed篇: 1. 删除指定的字符,比如 'a'-----$ sed 's/a//' file 2. 移除每一行的第一个字符----$ sed 's/^.//' file 3. 移除每一行的最后一个字符 ...

  4. 《深入剖析Nginx》 笔记

    nginx的编译安装使用Linux下通用的三板斧即可:./configure make make install 查看帮助选项./configure --help 禁用编译器优化方法一:CFLAGS= ...

  5. AVL tree rotate

    AVL tree single rotate /** * Rotate binary tree node with left child. * For AVL trees, this is a sin ...

  6. python测试IP地址是否ping通

    import timeimport osdef pingComputer(): for i in range(1, 256): host = '192.168.2.' + str(i) status1 ...

  7. 如何获取android环境自带的jar包

    首先找到你需要用到的类,Ctrl 并点击跳转到这个类 跳转过来之后,找到这个类所在的包 Ctrl并点击,此时会跳转到这个包所在的jar的位置 右键class.jar并选择在文件资源浏览器打开 打开以后 ...

  8. docker镜像原理(一)

    在理解什么是docker镜像之前我们需要搞懂虚拟机系统到底是怎么组成的如何实现的,docker中又是如何安装和使用虚拟机系统的,怎样可以高效灵活的切换系统发行版等问题 一.centos7系统长什么样 ...

  9. h5:vue3 + ts + vite + vuex + axios + vant4 + scss + postcss+mockjs+element-plus

    模板地址:https://gitee.com/zhang_meng_lei/mobile-template-h5-vue3/tree/master 1.安装element-plus:yarn add ...

  10. Linux进程调度算法

    进程的状态 进程的基本状态 就绪:进程已获得除处理机以外的所需资源,等待分配处理机资源 执行:进程正在占用处理机资源执行 阻塞:进程等待某种条件,在条件满足之前无法执行.例如发起I/O系统调用,等待I ...