28 lines
622 B
Python
28 lines
622 B
Python
|
||
|
||
def sub_dict(param1, param2):
|
||
"""
|
||
获取字典的子集
|
||
Parameters:
|
||
param1: 原字典
|
||
param2: 子集字段
|
||
Returns:
|
||
子集
|
||
"""
|
||
return dict((key, value) for key, value in param1.items() if key in param2)
|
||
|
||
|
||
def df_iterrows(param):
|
||
"""
|
||
按行以数组形式返回DataFrame的index、data
|
||
Parameters:
|
||
param: DataFrame 某个df对象
|
||
Returns:
|
||
result: list 遍历df对象每行数据,包括index
|
||
"""
|
||
result = []
|
||
for row in param.iterrows():
|
||
index, data = row
|
||
result.append([index] + data.tolist())
|
||
return result
|