0

I have a data frame that has a row type that has A,B,C in repeated ways and they belong to different values an example below

Type Value Volume brand 
A     1     5      E
B     2     1      $
C     3     1      5 
C     2     1      2  
C     4     5      7 
B     2     1      E
A     3     3      $

The outcome I am searching for is to produce a CSV for A B and C

A.csv =

Type Value Volume Brand
A     1      5      E
A     3      3      $

B.csv =

Type Value Volume Brand
 B     2      1      $
 B     2      1      E

C.csv =

Type Value Volume Brand
 C     3     1      5 
 C     2     1      2  
 C     4     5      7 

I know how to do this individually but I would like to learn a way to do this for all of them together like with a for because I have a data frame with 32 different types and doing them individually is not cost effficient so any help would be very valuable.

1

1 Answer 1

2

you can try this:

week_grouped = df.groupby('Type')

for name, group in week_grouped:
    print(name) # to get names of your group in this case A, B , C
    group.to_csv(f'{name}.csv')

check using

df_A=pd.read_csv('A.csv', index_col=0)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.