Pandas 按照某一列的值分割Dataframe

设有如下df

1
2
3
4
    target
0 1
1 2
2 3

我们希望可以将其根据target的值的不同,分为若干个子df,方法如下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
df_1 = df[df["target"].isin(["1"])]
print(df["target"].isin(["1"]))
"""
target
0 True
1 False
2 False
"""

print(df_1)
"""
target
0 1
"""