我有以下代码,它返回所选列的最小值和最大值,但是,我还想包括该值与之相关的物种。我还在csv文件中包含了列名。
import pandas as pd
import numpy as np
import scipy as sp
import matplotlib as mpl
import seaborn as sns
df = pd.read_csv("iris head.csv")
print(min(df['Sepal Length']))
print(max(df['Sepal Length']))
答案 0 :(得分:1)
IIUC如下:
df.groupby(['class'])['Sepal Length'].agg(['max','min'])