jm4.py-20180918

本文通过使用Python的数据分析库,如Pandas、Matplotlib、Seaborn等,对全球恐怖袭击事件进行深入分析。从时间趋势、地区分布、恐怖组织活动等方面展示了恐怖袭击事件的统计数据,并通过图表直观地呈现了各年的恐怖袭击事件数量变化。
#!/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))








 

【顶级EI完美复现】电力系统碳排放流的计算方法【IEEE 14节点】(Matlab代码实现)内容概要:本文介绍了名为《【顶级EI完美复现】电力系统碳排放流的计算方法【IEEE 14节点】(Matlab代码实现)》的技术文档,核心内容是基于IEEE 14节点电力系统模型,利用Matlab实现碳排放流的精确计算方法。该方法通过建立电力系统中各节点的功率流动与碳排放之间的映射关系,实现对电能传输过程中碳足迹的追踪与量化分析,属于电力系统低碳调度与碳流管理领域的关键技术。文中强调“顶级EI完美复现”,表明其算法和仿真结果具有较高的学术严谨性和可重复性,适用于科研验证与教学演示。; 适合人群:电力系统、能源与动力工程、电气工程及其自动化等相关专业的研究生、科研人员以及从事电力系统低碳化、碳排放核算工作的技术人员。; 使用场景及目标:①用于电力系统碳排放流理论的学习与仿真验证;②支撑含新能源接入的电力系统低碳调度、碳交易、绿色电力溯源等课题的研究;③为撰写高水平学术论文(如EI/SCI期刊)提供可靠的代码基础和技术参考。; 阅读建议:读者应具备电力系统分析、Matlab编程的基础知识,建议结合电力系统潮流计算、节点导纳矩阵等前置知识进行学习,并通过调整系统参数和运行方式,深入理解碳排放流的分布规律与影响因素。
(venv) gapinyc@DESKTOP-9QS7RL5:~/superset$ flask shell ?charset=utf8mb4ASE_URI: mysql+pymysql://superset_user Loaded your LOCAL configuration at [/home/gapinyc/superset/superset_config.py] 2025-10-25 07:16:58,944:DEBUG:superset.utils.logging_configurator:logging was configured successfully 2025-10-25 07:16:58,949:DEBUG:root:Configured event logger of type <class 'superset.utils.log.DBEventLogger'> 2025-10-25 07:16:58,952:INFO:superset.initialization:Setting database isolation level to READ COMMITTED 2025-10-25 07:16:58,953:ERROR:flask_appbuilder.security.sqla.manager:DB Creation and initialization failed: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '192.168.110.204\\r' ([Errno -2] Name or service not known)") (Background on this error at: https://sqlalche.me/e/14/e3q8) (venv) gapinyc@DESKTOP-9QS7RL5:~/superset$ cat -A /home/gapinyc/superset/.env # M-fM-^UM-0M-fM-^MM-.M-eM-:M-^SM-hM-?M-^^M-fM-^NM-%$ DB_HOST=192.168.110.204$ DB_PORT=3306$ DB_USER=superset$ DB_PASSWORD=password$ DB_NAME=superset$ $ # Superset M-iM-^EM-^MM-gM-=M-.$ SECRET_KEY=kNeeshADyj2cmejJjWqJf590qM2Hkf6LrspLE8dgzatDmogrn4a8SAma(venv) gapinyc@DESKTOP-9QS7RL5:~/superset$ cat -A /home/gapinyc/superset/superset_config.pycat -A /home/gapinyc/superset/superset_config.py | grep -A5 -B5 '\^M' import os^M$ ^M$ # -------------------------------^M$ # M-fM-^UM-0M-fM-^MM-.M-eM-:M-^SM-iM-^EM-^MM-gM-=M-.M-oM-<M-^ZM-dM-=M-?M-gM-^TM-( MySQL^M$ # -------------------------------^M$ SQLALCHEMY_DATABASE_URI = (^M$ f"mysql+pymysql://{os.getenv('MYSQL_USER')}:{os.getenv('MYSQL_PASSWORD')}"^M$ f"@{os.getenv('MYSQL_HOST')}/{os.getenv('DATABASE')}?charset=utf8mb4"^M$ )^M$ ^M$ print("SQLALCHEMY_DATABASE_URI:", SQLALCHEMY_DATABASE_URI)^M$ ^M$ # -------------------------------^M$ # Superset M-eM-^EM-^CM-fM-^UM-0M-fM-^MM-.M-fM-^UM-0M-fM-^MM-.M-eM-:M-^S URIM-oM-<M-^HM-eM-^MM-3M-hM-^GM-*M-hM-:M-+M-eM-^EM-^CM-fM-^UM-0M-fM-^MM-.M-eM--M-^XM-eM-^BM-(M-dM-=M-^MM-gM-=M-.M-oM-<M-^I^M$ # -------------------------------^M$ SQLALCHEMY_TRACK_MODIFICATIONS = False^M$ ^M$ # -------------------------------^M$ # Flask App Builder M-iM-^EM-^MM-gM-=M-.^M$ # -------------------------------^M$ SECRET_KEY = os.getenv('SUPERSET_SECRET_KEY', 'your-super-secret-key-change-in-prod')^M$ ^M$ # -------------------------------^M$ # M-iM-^BM-.M-dM-;M-6M-iM-^EM-^MM-gM-=M-.M-oM-<M-^HM-eM-^OM-/M-iM-^@M-^IM-oM-<M-^I^M$ # -------------------------------^M$ # M-eM-&M-^BM-fM-^^M-^\M-iM-^\M-^@M-hM-&M-^AM-eM-^OM-^QM-iM-^BM-.M-dM-;M-6M-eM-^QM-^JM-hM--M-&M-gM--M-^IM-eM-^JM-^_M-hM-^CM-=M-oM-<M-^LM-hM-/M-7M-iM-^EM-^MM-gM-=M-.^M$ # MAIL_SERVER = 'localhost'^M$ # MAIL_USE_TLS = False^M$ # MAIL_USERNAME = 'no-reply@example.com'^M$ # MAIL_PASSWORD = ''^M$ # MAIL_DEFAULT_SENDER = 'no-reply@example.com'^M$ ^M$ # -------------------------------^M$ # M-iM-^]M-^YM-fM-^@M-^AM-hM-5M-^DM-fM-:M-^PM-eM-^RM-^LM-gM-<M-^SM-eM--M-^XM-oM-<M-^HM-eM-^OM-/M-iM-^@M-^IM-dM-<M-^XM-eM-^LM-^VM-oM-<M-^I^M$ # -------------------------------^M$ # DATA_CACHE_CONFIG = {^M$ # 'CACHE_TYPE': 'simple'^M$ # } (venv) gapinyc@DESKTOP-9QS7RL5:~/superset$ sed -i 's/\r$//' /home/gapinyc/superset/superset_config.py (venv) gapinyc@DESKTOP-9QS7RL5:~/superset$ cat -A /home/gapinyc/superset/superset_config.py | grep -A5 -B5 '\^M' import os$ $ # -------------------------------$ # M-fM-^UM-0M-fM-^MM-.M-eM-:M-^SM-iM-^EM-^MM-gM-=M-.M-oM-<M-^ZM-dM-=M-?M-gM-^TM-( MySQL$ # -------------------------------$ SQLALCHEMY_DATABASE_URI = ($ f"mysql+pymysql://{os.getenv('MYSQL_USER')}:{os.getenv('MYSQL_PASSWORD')}"$ f"@{os.getenv('MYSQL_HOST')}/{os.getenv('DATABASE')}?charset=utf8mb4"$ )$ $ print("SQLALCHEMY_DATABASE_URI:", SQLALCHEMY_DATABASE_URI)$ $ # -------------------------------$ # Superset M-eM-^EM-^CM-fM-^UM-0M-fM-^MM-.M-fM-^UM-0M-fM-^MM-.M-eM-:M-^S URIM-oM-<M-^HM-eM-^MM-3M-hM-^GM-*M-hM-:M-+M-eM-^EM-^CM-fM-^UM-0M-fM-^MM-.M-eM--M-^XM-eM-^BM-(M-dM-=M-^MM-gM-=M-.M-oM-<M-^I$ # -------------------------------$ SQLALCHEMY_TRACK_MODIFICATIONS = False$ $ # -------------------------------$ # Flask App Builder M-iM-^EM-^MM-gM-=M-.$ # -------------------------------$ SECRET_KEY = os.getenv('SUPERSET_SECRET_KEY', 'your-super-secret-key-change-in-prod')$ $ # -------------------------------$ # M-iM-^BM-.M-dM-;M-6M-iM-^EM-^MM-gM-=M-.M-oM-<M-^HM-eM-^OM-/M-iM-^@M-^IM-oM-<M-^I$ # -------------------------------$ # M-eM-&M-^BM-fM-^^M-^\M-iM-^\M-^@M-hM-&M-^AM-eM-^OM-^QM-iM-^BM-.M-dM-;M-6M-eM-^QM-^JM-hM--M-&M-gM--M-^IM-eM-^JM-^_M-hM-^CM-=M-oM-<M-^LM-hM-/M-7M-iM-^EM-^MM-gM-=M-.$ # MAIL_SERVER = 'localhost'$ # MAIL_USE_TLS = False$ # MAIL_USERNAME = 'no-reply@example.com'$ # MAIL_PASSWORD = ''$ # MAIL_DEFAULT_SENDER = 'no-reply@example.com'$ (venv) gapinyc@DESKTOP-9QS7RL5:~/superset$ flask shell ?charset=utf8mb4ASE_URI: mysql+pymysql://superset_user Loaded your LOCAL configuration at [/home/gapinyc/superset/superset_config.py] 2025-10-25 07:18:41,114:DEBUG:superset.utils.logging_configurator:logging was configured successfully 2025-10-25 07:18:41,120:DEBUG:root:Configured event logger of type <class 'superset.utils.log.DBEventLogger'> 2025-10-25 07:18:41,122:INFO:superset.initialization:Setting database isolation level to READ COMMITTED 2025-10-25 07:18:41,123:ERROR:flask_appbuilder.security.sqla.manager:DB Creation and initialization failed: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '192.168.110.204\\r' ([Errno -2] Name or service not known)") (Background on this error at: https://sqlalche.me/e/14/e3q8) (venv) gapinyc@DESKTOP-9QS7RL5:~/superset$
10-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值