import pandas as pd
# 假设 df 是你的 DataFrame,column_name 是你要排序的字段名
# 假设要提取 1% 到 99% 之间的数据
# 对 DataFrame 根据指定字段进行升序排序
sorted_df = df.sort_values(by=column_name)
# 计算 DataFrame 的总行数
total_rows = len(sorted_df)
# 计算前 1% 和后 1% 的行数
top_1_percent_rows = int(total_rows * 0.01)
bottom_1_percent_rows = int(total_rows * 0.99)
# 提取 1% 到 99% 之间的数据
middle_data = sorted_df.iloc[top_1_percent_rows:bottom_1_percent_rows]
dataFrame 根据某个字段升序排序 提取前1%到99%中间的数据
最新推荐文章于 2024-07-25 23:19:30 发布
该篇文章介绍了如何使用Python的pandas库对DataFrame进行排序,特别关注了如何提取数据集中1%到99%的数据范围。首先对DataFrame按指定字段升序排序,然后计算总行数,进而确定前1%和后1%的行数,最后使用iloc方法获取中间数据部分。
摘要由CSDN通过智能技术生成