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

  1. import pandas as pd
  2. import sqlite3
  3. import networkx as nx
  4. import time
  5. import numpy as np
  6. def gen_dict(sql):#建立投票数据字典
  7. votedict={}
  8. votedict['all']={}
  9. for c in cntylist:
  10. votedict['all'][c]={}
  11. votedict['all'][c]['yes']=[]
  12. votedict['all'][c]['noyes']=[]
  13. votedict['all'][c]['qq']=[]
  14. votedict['all'][c]['no']=[]
  15. votedict['all'][c]['all']=[]
  16. for y in [199220012010]:
  17. votedict[y]={}
  18. for c in cntylist:
  19. votedict[y][c]={}
  20. votedict[y][c]['yes']=[]
  21. votedict[y][c]['noyes']=[]
  22. votedict[y][c]['qq']=[]
  23. votedict[y][c]['no']=[]
  24. votedict[y][c]['all']=[]
  25. for c in cntylist:
  26. c1=c
  27. r1sql='select rcid, Country, vote, year from data where vote<4 and Country= \'%s\'' % c1 + sql
  28. rec1=pd.read_sql(r1sql conn
  29. yeslist=rec1[rec1['vote']==1]['rcid'].tolist()
  30. noyeslist=rec1[(rec1['vote']==2)|(rec1['vote']==3)]['rcid'].tolist()
  31. nolist=rec1[rec1['vote']==3]['rcid'].tolist()
  32. qqlist=rec1[rec1['vote']==2]['rcid'].tolist()
  33. votedict['all'][c]['yes']=yeslist
  34. votedict['all'][c]['noyes']=noyeslist
  35. votedict['all'][c]['qq']=qqlist
  36. votedict['all'][c]['no']=nolist
  37. votedict['all'][c]['all']=rec1['rcid'].tolist()
  38. for y in [199220012010]:
  39. for c in cntylist:
  40. c1=c
  41. yearsql='and year>= %d and year< %d'%(yy+8
  42. r1sql='select rcid, Country, vote, year from data where vote<4 and Country= \'%s\'' % c1+yearsql+sql
  43. rec1=pd.read_sql(r1sql conn
  44. yeslist=rec1[rec1['vote']==1]['rcid'].tolist()
  45. noyeslist=rec1[(rec1['vote']==2)|(rec1['vote']==3)]['rcid'].tolist()
  46. nolist=rec1[rec1['vote']==3]['rcid'].tolist()
  47. qqlist=rec1[rec1['vote']==2]['rcid'].tolist()
  48. votedict[y][c]['yes']=yeslist
  49. votedict[y][c]['noyes']=noyeslist
  50. votedict[y][c]['qq']=qqlist
  51. votedict[y][c]['no']=nolist
  52. votedict[y][c]['all']=rec1['rcid'].tolist()
  53. print(sqly'生成该年份数据'
  54. print(sql'数据字典已经生成'
  55. return votedict
  56. def ivc_gen_new(thedictc1c2):#基于字典计算两国间IVC
  57. c1yes= thedict[c1]['yes']
  58. c1no= thedict[c1]['no']
  59. c1noyes=thedict[c1]['noyes']
  60. c1qq=thedict[c1]['qq']
  61. c2yes= thedict[c2]['yes']
  62. c2no=thedict[c2]['no']
  63. c2noyes=thedict[c2]['noyes']
  64. c2qq=thedict[c2]['qq']
  65. c1all=thedict[c1]['all']
  66. c2all=thedict[c2]['all']
  67. 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]
  68. glist=[x for x in c1qq if x in c2yes+c2no]+[x for x in c2qq if x in c1yes+c1no]
  69. f=len(set(flist))
  70. g=len(set(glist))
  71. t=len(set([c for c in c1all if c in c2all]))
  72. try:
  73. ivc=(f+0.5*g)/t
  74. except:
  75. ivc=0
  76. 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. FFmpeg转换直播流格式

    mp4转rtsp ffmpeg -re -i 1671680590843.mp4 -vcodec copy -acodec copy -f rtsp rtsp://localhost:8554/liv ...

  2. ROS创建工作空间 Create your workspace

    https://blog.csdn.net/baidu_38869387/article/details/119840120 http://wiki.ros.org/catkin/Tutorials/ ...

  3. ELKF搭建

    logstash cat /etc/logstash/logstash.yml |grep -v '#'path.data: /data/logstash/datapipeline.ordered: ...

  4. 【RUNOOB】C语言学习之指针

    资料来源: (1) runoob; (2) C语言程序设计; 注1:Runoob中对于指针的讲述比较清晰简单,摘录出来(后续补充指针与结构体,指针与函数参数); 1.指针与变量的内存位置 (1) 每个 ...

  5. 深入理解 epoll 原理

    从网卡如何接收数据说起 CPU 如何知道接受了数据? 进程阻塞为什么不占用 CPU 资源? 工作队列 等待队列 唤醒进程 内核接收网络数据全过程 同时监视多个 socket 的方法 select 的监 ...

  6. python学习:sqlite3 文件型数据库

    摘录:https://www.cnblogs.com/decwang/p/4565572.html SQLite 字段类型 一般数据采用的固定的静态数据类型,而SQLite采用的是动态数据类型,会根据 ...

  7. Spring Boot上传文件功能的开发

    Spring Boot上传文件功能的开发 Spring Boot使用Servlet 3的API javax.servlet.http.Part来支持文件上传.Spring Boot在类Multipar ...

  8. composer 操作

    composer list 显示所有命令 composer show 显示所有包信息 composer install 在 composer.json 配置中添加依赖库之后运行此命令安装 compos ...

  9. Jquery EasyUI dataGrid 修改默认分页大小 不起效果

    pageSize 不能单独使用,必须和pageList联合使用. 如果pageSize的值不在pageList中时,会以pageList中最小的值显示,而设置的pageSize无效.

  10. 实践:带您用多种姿势将存储在腾讯云COS 上的视频播放

    导语 随着5G时代的到来,短视频/直播行业开始流行,音视频逐渐成为信息传播中流量占比最大的部分.腾讯云对象存储(COS)作为可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务,早已不 ...