发布于2019-09-11 14:38 阅读(1134) 评论(0) 点赞(4) 收藏(0)
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Mon Sep 17 12:46:07 2018
- @author: vicky
- """
-
- import pandas as pd
- import matplotlib.pyplot as plt
- import matplotlib.patches as mpatches
- import seaborn as sns
- import numpy as np
- plt.style.use('fivethirtyeight')
- import plotly.offline as py
- py.init_notebook_mode(connected=True)
- import plotly.graph_objs as go
- import plotly.tools as tls
- from mpl_toolkits.basemap import Basemap
- import folium
- import folium.plugins
- from matplotlib import animation,rc
- import io
- import base64
- from IPython.display import HTML, display
- import warnings
- from scipy.misc import imread
- import codecs
- from subprocess import check_output
- from pandas.core.frame import DataFrame
-
-
- df = pd.read_excel('/Users/vicky/Desktop/建模/附件1.xlsx')
-
- col_t=['iyear','imonth','iday','country_txt','region_txt','attacktype1_txt','target1','nkill','nwound','summary','gname',
- 'targtype1_txt','weaptype1_txt','motive']
- terror=df[col_t]
- terror.rename(columns={'iyear':'Year','imonth':'Month','iday':'Day','country_txt':'Country','region_txt':'Region',
- 'attacktype1_txt':'AttackType','target1':'Target','nkill':'Killed','nwound':'Wounded','summary':'Summary',
- 'gname':'Group','targtype1_txt':'Target_type','weaptype1_txt':'Weapon_type','motive':'Motive'},inplace=True)
- terror['casualities']=terror['Killed']+terror['Wounded']
-
- terror.head(3)
- terror.isnull().sum()
-
- #terror=terror[terror['Year'] > 2014]
-
- #各年总数
- plt.subplots(figsize=(10,6))
- sns.countplot('Year',data=terror,palette='RdYlGn_r',edgecolor=sns.color_palette('dark',7))#计数图
- plt.xticks(rotation=90)
- plt.title('Number Of Terrorist Activities Each Year')
- plt.show()
- num=DataFrame(terror['Year'].value_counts())
- num.plot(color=sns.color_palette('Set2',12))
- num2=pd.concat([DataFrame(num)],axis=1)
- DataFrame(num).plot(color=sns.color_palette('Set2',12))
- num3=DataFrame(num_for.num,index=range(1998,2021),dtype=int)
- num3.num=num_for.num
-
- ##各年分地区总数
- #plt.subplots(figsize=(10,6))
- #sns.countplot('Region',data=terror,palette='RdYlGn',edgecolor=sns.color_palette('dark',7),order=terror['Region'].value_counts().index)
- #plt.xticks(rotation=90)
- #plt.title('Number Of Terrorist Activities By Region')
- #plt.show()
-
- #各年分地区数量
- terror_region=pd.crosstab(terror.Year,terror.Region)
- terror_region.plot(color=sns.color_palette('Set2',12))
- fig=plt.gcf()
- fig.set_size_inches(10,6)
- plt.show()
-
- #各年top恐怖组织数量
- top_groups10=terror[terror['Group'].isin(terror['Group'].value_counts()[1:11].index)]
- group10=pd.crosstab(top_groups10.Year,top_groups10.Group)
- group10.plot(color=sns.color_palette('Paired',10))
- fig=plt.gcf()
- fig.set_size_inches(10,6)
- plt.show()
-
- r=region_f.ix[20:25,1:]
- r2=pd.concat([group10,r],axis=0)
- r2.index=range(1998,2023)
- r2.plot(color=sns.color_palette('Paired',10))
-
-
-
-
-
-
-
-
作者:喜洋洋与红太狼
链接:https://www.pythonheidong.com/blog/article/107314/cd6e4a270cca69500774/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!