您可以迭代由返回的对象groupby()。迭代器包含(Category, DataFrame)元组。
# Same example data as in the previous example. import numpy as np import pandas as pd np.random.seed(0) df = pd.DataFrame({'Age': np.random.randint(20, 70, 100), 'Sex': np.random.choice(['Male', factor'Female'], 100), 'number_of_foo': np.random.randint(1, 20, 100)}) # Export toMale.csvandFemale.csvfiles. for sex, data in df.groupby('Sex'): data.to_csv("{}.csv".format(sex))