本项目是一个含有多功能的数据集,里面有很多数据集,目前已经上传到Pypi。
本项目使用Pypi,所以建议使用Pypi下载
有一些依赖库,请将以下代码粘贴到终端
pip3 install simplejson
pip3 install openpyxl
pip3 install matplotlib
pip3 install setuptools
代码:pip3 install Wdatabase
我们上传时包名和实际使用时用的包名不太一样 导入时,使用以下代码
from Wdata import WdataMain as main主类中有以下函数:
| 函数 | 介绍 | 语法 | 返回类型 |
|---|---|---|---|
| draw | 绘图 | Func() | None |
| Save_file | 保存文档 | Func(filename:str, type='json', Sheet='Data', RowOrColumn=True) | bool |
Wdata有很多数据集,我们这里使用200年来人口增长数据举例
Wdata_class的语法如下:
Wdata_class(json_fname: str)
json_fname为数据集的名字
from Wdata import WdataMain as main
test = main('Population_growth') # 导入200年来人口增长我们可以使用Fetch_dict函数获取数据
比如这些代码
from Wdata import WdataMain as main
test = main('Population_growth') # 导入200年来人口增长
print(dict(test))运行后
~/python test.py
{
'1800': 900000000,
'1820': 1100000000,
'1840': 1200000000,
'1860': 1300000000,
'1880': 1400000000,
'1900': 1650000000,
'1920': 1800000000,
'1940': 2200000000,
'1960': 3000000000,
'1980': 4400000000,
'2000': 5900000000,
'2022': 7400000000
}绘图功能使用draw()函数
如以下代码
from Wdata import WdataMain as main
test = main('Population_growth') # 导入200年来人口增长
test.draw()你可以使用Save_file()函数来保存数据
Save_file的语法是Save_file(filename:str, type='json', Sheet='Data', RowOrColumn=True) -> None
参数说明:
filename参数是用于说明保存文件
type参数是用于说明文件类型
Sheet只在保存.xlsx文件时生效,表示保存的工作表
RowOrColumn只在保存.xlsx文件时生效,表示保存的格式
文件类型有以下几个:
| 文件类型 | 使用方式 | 说明 |
|---|---|---|
| csv | Wdata.CSV | 保存文件file.csv |
| json | Wdata.JSON | 保存文件file.json,为默认选项 |
| xlsx | Wdata.XLSX | 保存文件file.xlsx |
保存JSON文件的代码
from Wdata import WdataMain as main
from Wdata import CSV
test = main('Population_growth') # 导入200年来人口增长
test.Save_file('Package_test') # 默认选项保存CSV文件的代码
from Wdata import WdataMain as main
test = main('Population_growth') # 导入200年来人口增长
test.Save_file('Package_test', CSV) # 该函数会自动添加.csv后缀保存.xlsx文件会使用到Sheet和RowOrColumn参数
Sheet表示保存单元格,默认为Data
RowOrColumn表示保存形式,默认为True
from Wdata import WdataMain as main
from Wdata import XLSX
test = main('Population_growth') # 导入200年来人口增长
test.Save_file('Package_test', XLSX) # 该函数会自动添加.xlsx后缀
# test.Save_file('Package_test', XLSX, RowOrColumn=False) 这条代码会以列的形式保存当RowOrColumn为True时,保存形式是这样的
| 1820 | 1840 | 1860 | 1880 | 1900 | 1920 | 1940 | 1960 | 1980 | 2000 | 2022 |
|---|---|---|---|---|---|---|---|---|---|---|
| 1100000000 | 1200000000 | 1300000000 | 1400000000 | 1650000000 | 1800000000 | 2200000000 | 3000000000 | 4400000000 | 5900000000 | 7400000000 |
反之,是这样的
| 1820 | 1100000000 |
|---|---|
| 1840 | 1200000000 |
| 1860 | 1300000000 |
| 1880 | 1400000000 |
| 1900 | 1650000000 |
| 1920 | 1800000000 |
| 1940 | 2200000000 |
| 1960 | 3000000000 |
| 1980 | 4400000000 |
| 2000 | 5900000000 |
| 2022 | 7400000000 |
余弦相似度函数可以根据余弦相似度公式计算出二维空间中两个坐标的余弦相似度
使用方法:
from Wdata import mathfunc
xy1 = (2, 3) # 第一个坐标
xy2 = (3, 5) # 第二个坐标
result = mathfunc.similarity(xy1, xy2) # 余弦相似度
print(result)距离公式使用欧几里得距离公式计算出二维空间中两个坐标的距离
使用方法:
from Wdata import mathfunc
xy1 = (2, 3)
xy2 = (3, 5)
result = mathfunc.distance(xy1, xy2) # 距离公式
print(result)目前我们有以下数据
| 名字 | 说明 | 计量单位 |
|---|---|---|
| Population_growth | 1800-2022年人口增长 | 人 |
| Chinese_spacecraft | 2017-2020.06中国航天器发射次数 | 航天器 |
| World_spacecraft | 2017-2020.06世界航天器发射次数 | 航天器 |
以上数据来源于Bing以及Baidu,作者无法确保数据的准确性,切勿用于专业用途
由于特殊原因,作者无法注册Paypal账号,被迫使用支付宝
具体详情请见捐款说明
Wdataorg团队已经使用twine将本库上传到Pypi
本开源项目使用Apache License 2.0
在使用本开源项目过程中,请严格按照许可证规定使用
最终解释权归开发团队Wdataorg所有
0.0.1b0版本已经发布,各位使用者可以提出自己宝贵的意见
如何内测?
请按照README指示下载项目并且使用,填写内测单
