Python 3.x Pandas按列值将数据帧拆分为两个数据帧-不使用GroupBy

Python 3.x Pandas按列值将数据帧拆分为两个数据帧-不使用GroupBy,python-3.x,pandas,Python 3.x,Pandas,我想根据列值将我的Pandas dataframe按行拆分为两个dataframe 对于行可以按列值分组的情况,有许多问题和答案 但是,在我的例子中,我希望在特定列中具有唯一字符串的行上拆分数据帧 我的计划是获得具有唯一列值的行的行索引,如下所示: split_row_index = df[df['column name']=='unique string'].index.item() df_1 = df.iloc[:split_row_index ] df_2 = df.iloc[split

我想根据列值将我的Pandas dataframe按行拆分为两个dataframe

对于行可以按列值分组的情况,有许多问题和答案

但是,在我的例子中,我希望在特定列中具有唯一字符串的行上拆分数据帧

我的计划是获得具有唯一列值的行的行索引,如下所示:

split_row_index = df[df['column name']=='unique string'].index.item()
df_1 = df.iloc[:split_row_index ]
df_2 = df.iloc[split_row_index :]
然后使用获得的行索引,将数据帧拆分为两个数据帧,如下所示:

split_row_index = df[df['column name']=='unique string'].index.item()
df_1 = df.iloc[:split_row_index ]
df_2 = df.iloc[split_row_index :]
我的数据框没有列名,因此我不能使用
df[df['column name']
,而是要使用列索引指定要搜索的列

我正在努力获取语法,以便通过索引来识别它。我尝试了以下不起作用的方法:

split_row_index = df[df[0]=='unique string'].index.item()
split_row_index = df[df.loc[0]=='unique string'].index.item()

选择数据帧列值并同时获取索引的正确语法是什么?

然后更改为
iloc

split_row_index = df[df.iloc[:,0]=='unique string'].index.item()