- 这个系列讲讲Python的科学计算版块
- 今天讲讲pandas模块:获取某列的一些统计结果,包括最大/最小值/均值/标准方差等
Part 1:示例
DataFrame
,有4列["quality_1", "measure_value", "up_tol", "down_tol"]
Part 2:代码
import pandas as pd
dict_1 = {"quality_1": ["pos_1", "pos_2", "pos_3", "pos_4", "pos_5"],
"measure_value": ["6", "4", 6, 3.5, 2.5],
"up_tol": [5, 5, 3, 3, 2],
"down_tol": [-5, -5, -3, -3, 2]}
df = pd.DataFrame(dict_1, columns=["quality_1", "measure_value", "up_tol", "down_tol"])
print(df)
statistic_value = df.describe()
print(statistic_value)
print("\n", "数据类型转换后")
df[["measure_value"]] = df[["measure_value"]].astype(float)
print(df)
statistic_value = df.describe()
print(statistic_value)
Part 3:部分代码解读
statistic_value = df.describe()
,对数值列进行统计计算,输出结果分类:df[["measure_value"]] = df[["measure_value"]].astype(float)
,对measure_value
列进行数据类型转换
最新评论