Q:

pandas for loop to export file include all the condition

import pandas as pd
from io import StringIO

mystr = StringIO("""beat,crimedescr
A,10851(A)VC TAKE VEH W/O OWNER
B,459 PC  BURGLARY RESIDENCE
C,10851(A)VC TAKE VEH W/O OWNER
A,476 PC PASS FICTICIOUS CHECK
B,459 PC  BURGLARY-UNSPECIFIED
C,530.5 PC USE PERSONAL ID INFO""")

df = pd.read_csv(mystr, header=0)

for i in df.beat.unique():
    df.loc[df.beat==i].to_csv(f'{i}.csv', index=False)

I'd like to export 4 csv files from this dataframe including:
A file with the entire dataframe and 3 separate files (A,B,C). 
I know it's possible to simply df.to_csv and add another for loop. 
How to do it in strictly one for loop since most of time the condition is very complicated in df.loc[()&()..] which separated export made codes very hard to read?

A:

try this,
for u, v in df.groupby('beat'):
    v.to_csv(u+'.csv',index=False)
df.to_csv('all.csv',index=False)

Edit-1: For single loop
flag=True
for u, v in df.groupby('beat'):
    if flag:
        df.to_csv('all.csv',index=False)
        flag=False
    v.to_csv(u+'.csv',index=False)

