some utils to process data easy
Project description
data_factory
数据处理模块,主要是一些处理字典的函数
search
搜索字典中的键值对,如果有多个相同的键,值会被放到一个列表。
参数及其类型
-
key :
str, list, tuple -
data :
dict
用法:
data = {
'name':'search',
'intro':'search key/value in dict data',
'desc':{
'name':'find',
'intro':'find something'
}
}
print(search('name', data))
# output: ['search', 'find']
print(search(['name','intro'], data))
# output: {'name': ['search', 'find'], 'intro': ['search key/value in dict data', 'find something']}
update
更新字典中的键值对。
参数及其类型
- update_map :
dict - data :
dict - target_type :
str, tuple
用法:
data = {
'name':'search',
'intro':'search key/value in dict data',
'desc':{
'name':'find',
'intro':'find something'
}
}
print(update({'name': 'PYTHON'}, data=data))
# output: {'name': 'PYTHON', 'intro': 'search key/value in dict data', 'desc': {'name': 'PYTHON', 'intro': 'find something'}}
print(update({'name': 'PYTHON'}, data=data, target_type=int))
# output: {'name': 'search', 'intro': 'search key/value in dict data', 'desc': {'name': 'find', 'intro': 'find something'}}
target_type 字段标明更新字段的类型,默认更新类型:str, bytes, int, float, list, dict,如果字典的值的类型不在更新类型范围内,则不更新值。
replace
替换字典中的键值对。
参数及其类型
- replace_map :
dict - data :
dict - replace_key :
bool
用法:
data = {
'name':'search',
'intro':'search key/value in dict data',
'desc':{
'name':'find',
'intro':'find something'
}
}
print(replace({'find': 'search'}, data=data))
# output: {'name': 'search', 'intro': 'search key/value in dict data', 'desc': {'name': 'search', 'intro': 'search something'}}
print(replace({'name': 'Name'}, data=data, replace_key=True))
# output: {'Name': 'search', 'intro': 'search key/value in dict data', 'desc': {'Name': 'find', 'intro': 'find something'}}
strip
清洗字典
参数及其类型
- *args :
str - data :
dict - strip_key :
bool
用法:
data = {
'name':'search',
'intro':'search key/value in dict data',
'desc':{
'name':'find',
'intro':'find something'
}
}
print(strip('key/', 'find', data=data))
# output: {'name': 'search', 'intro': 'search value in dict data', 'desc': {'name': '', 'intro': ' something'}}
print(strip('ame', data=data, strip_key=True))
# output: {'n': 'search', 'intro': 'search key/value in dict data', 'desc': {'n': 'find', 'intro': 'find something'}}
delete
删除键值对
参数及其类型
- *args :
str - data :
dict - target_type :
str, tuple
用法:
data = {
'name':'search',
'intro':'search key/value in dict data',
'desc':{
'name':'find',
'intro':'find something'
}
}
print(delete('desc', data=data))
# output: {'name': 'search', 'intro': 'search key/value in dict data'}
默认target_key 类型为 str, bytes, int, float, list, dict
flatten
展开字典
参数及其类型
- data :
dict
用法:
data = {
'name':'search',
'intro':'search key/value in dict data',
'desc':{
'Name':'find',
'Intro':'find something'
}
}
print(dict(flatten(data)))
# output: {'name': 'search', 'intro': 'search key/value in dict data', 'Name': 'find', 'Intro': 'find something'}
merge
合并字典
参数及其类型
- *args :
dict - overwrite :
bool
用法:
data1 = {
'name':'search',
'intro':'search key/value in dict data',
'desc':{
'Name':'find',
'Intro':'find something'
}
}
data2 = {
'name':'find',
'intro':'searching',
'desc':{
'Name':'search',
'Intro':'find something'
}
}
print(merge(data1, data2))
# output: {'name': ['search', 'find'], 'intro': ['search key/value in dict data', 'searching'], 'desc': {'Name': ['find', 'search'], 'Intro': ['find something', 'find something']}}
print(merge(data1, data2, overwrite=True))
# output: {'name': ['search', 'find'], 'intro': ['search key/value in dict data', 'searching'], 'desc': {'Name': ['find', 'search'], 'Intro': ['find something']}}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Dtautils-0.8.16.tar.gz.
File metadata
- Download URL: Dtautils-0.8.16.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39b87d2cb54d3c15220e8f4a161d10569654788c04de556b12aa44454d28ae27
|
|
| MD5 |
3d36fae94c88f804b477509bd8efeaf1
|
|
| BLAKE2b-256 |
4e49a5506f2a1b06976ee8f09f74a2b1f630cde443f8c6bbb406fa30d6bbc659
|
File details
Details for the file Dtautils-0.8.16-py2.py3-none-any.whl.
File metadata
- Download URL: Dtautils-0.8.16-py2.py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
956775123ba9bfe1e61277331c45994c4d00b56d561e0fc1318143ca50368a75
|
|
| MD5 |
f4cdc7037be82c6446621eec5db14dd6
|
|
| BLAKE2b-256 |
8fc9d03567e145a3826c83201336c76091c720aa8b48f964f98d4df622ecf59f
|