pandas中计算相关系数
DataFrame.corr(method=’pearson’, min_periods=1)
Series中频数统计value_counts
Series.value_counts()
pandas中计算min和max
Series


DataFrame


pandas中循环迭代
Series

DataFrame



pandas选择除某几列之外的列

pandas中index的顺序
方法一


方法二
# 排序行
df = df.reindex(index=df.index.sort_values())
# 排序列
df = df.reindex(columns=df.columns.sort_values())

pandas中排序
Series


DataFrame

pandas中shuffle数据

DataFrame指定行或列进行操作
df[‘name’]=df[‘name’].apply(func)
pandas中DataFrame去重
pandas.drop_duplicates()

Series转DataFrame

(有用)DataFrame转dict

import pandas as pd
if __name__ == "__main__":
dict_list = [{"col_1": "a", "col_2": "2"}, {"col_1": "b", "col_2": "4"}, {"col_1": "c", "col_2": "6"}]
df = pd.DataFrame(dict_list, index=["row_1", "row_2", "row_3"])
print(df)
print()
print(">>>dict")
print(df.to_dict(orient="dict"))
print(">>>list")
print(df.to_dict(orient="list"))
print(">>>series")
print(df.to_dict(orient="series"))
print(">>>split")
print(df.to_dict(orient="split"))
print(">>>records")
print(df.to_dict(orient="records"))
print(">>>index")
print(df.to_dict(orient="index"))
输出结果如下:
col_1 col_2
row_1 a 2
row_2 b 4
row_3 c 6
>>>dict
{'col_1': {'row_1': 'a', 'row_2': 'b', 'row_3': 'c'}, 'col_2': {'row_1': '2', 'row_2': '4', 'row_3': '6'}}
>>>list
{'col_1': ['a', 'b', 'c'], 'col_2': ['2', '4', '6']}
>>>series
{'col_1': row_1 a
row_2 b
row_3 c
Name: col_1, dtype: object, 'col_2': row_1 2
row_2 4
row_3 6
Name: col_2, dtype: object}
>>>split
{'index': ['row_1', 'row_2', 'row_3'], 'columns': ['col_1', 'col_2'], 'data': [['a', '2'], ['b', '4'], ['c', '6']]}
>>>records
[{'col_1': 'a', 'col_2': '2'}, {'col_1': 'b', 'col_2': '4'}, {'col_1': 'c', 'col_2': '6'}]
>>>index
{'row_1': {'col_1': 'a', 'col_2': '2'}, 'row_2': {'col_1': 'b', 'col_2': '4'}, 'row_3': {'col_1': 'c', 'col_2': '6'}}
pandas中随机采样部分行
DataFrame.sample为不放回采样

