用于处理提交给PDI的数据的库。

openpdi的Python项目详细描述


打开pdiBuild Statuscode styleDOIThanks

openpdi是一项非正式的工作,它记录和标准化提交给 Police Data Initiative(pdi)。目标是使数据更容易访问 通过解决与 即标准化,

  • 文件类型:一些代理使用 Socrata Open Data API,许多人提供他们的数据 在不同结构的原始.csv.xlsx.xls文件中。
  • 列名:表示相同数据的许多列(例如,race 警察)在不同的部门、城市和州有不同的名字。
  • 值格式:在 很多不同的格式。
  • 列可用性:当前很难识别数据 包含某些列的源-例如使用force数据 指明有关人员的雇用日期。

开始

安装
$ pip install openpdi
用法
DatasetIDSource
Use of Force^{}https://www.policedatainitiative.org/datasets/use-of-force/
importcsvimportopenpdi# The library has a single entry point:dataset=openpdi.Dataset(# The dataset ID (see the table above)."uof",# Limit the data sources to a specific state using its two-letter code.## Default: `scope=[]`.scope=["TX"],# A list of columns that must be provided in every data source included in# this dataset. See `openpdi/meta/{ID}/schema.json` for the available# columns.## Default: `columns=[]`.columns=["reason"],# If `True`, only return the user-specified columns -- i.e., those listed# in the `columns` parameter.## Default: `strict=False`.strict=False)# The names of the agencies included in this dataset:print(dataset.agencies)# The URLs of the external data sources inlcuded in this dataset:print(dataset.sources)# `gen` is a generator object for iterating over the CSV-formatted dataset.gen=dataset.download()# Write to a CSV file:withopen("dataset.csv","w+")asf:writer=csv.writer(f,delimiter=",",quoting=csv.QUOTE_ALL)writer.writerows(gen)

数据集

为了避免不必要的膨胀(就gbs而言),我们实际上不在此存储库中存储任何pdi数据。相反,我们存储外部托管数据集的小的、json格式的描述,例如,^{}

[{"url":"https://www.norwichct.org/Archive.aspx?AMID=61&Type=Recent","type":"csv","start":1,"columns":{"date":{"index":0,"specifier":"%m/%d/%Y"},"city":{"raw":"Richmond"},"state":{"raw":"CA"},"service_type":{"index":1},"force_type":{"index":10},"light_conditions":{"index":8},"weather_conditions":{"index":7},"reason":{"index":2},"officer_injured":{"index":6},"officer_race":{"index":9},"subject_injured":{"index":5},"aggravating_factors":{"index":3},"arrested":{"index":4}}}]

此文件描述了来自加利福尼亚州里士满的force(uof)数据集的使用。数组中的每个条目都将一列从外部托管数据映射到数据集架构文件(^{})中的一列。

flow

schema.json文件将format分配给特定数据集中的每个可能的列,这是一个python函数,负责标准化原始列值(请参见^{})。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Cassandra复制因子大于节点数   java J2EE JTA事务回滚不适用于OSE Glassfish 4.0(Build 89)   java spring安全预认证用户登录   org的java类文件。反应流。从RxJava编译示例时未找到Publisher?   java在使用dataFormat作为POJO通过Camel调用Web服务时无法设置SOAP标头   Javafx类的java静态实例   java如何防止一个部件在关闭时覆盖另一个部件的位置   sql server无法从我的java代码连接到数据库   java在JList(Swing)中显示带有的ArrayList   从Java中的CXF服务获取WSAddressing数据   使用资产文件夹进行java简单json解析(本地)   java LDAPException未绑定的无效凭据   JavaJSFspring部署到weblogic   JAVA中字符数组中的特定元素排列?   如果脚本位于不同的目录中,则ant不会使用exec标记运行Javashell脚本