Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- df = pd.DataFrame({
- 'type':['coupe', 'combi', 'coupe', 'combi', 'coupe', 'combi'],
- 'rating':['A', 'A', 'B', 'B', 'A', 'C']
- })
- # --- selection ---
- new_df = df[ (df['type'] == 'coupe') & (df['rating'] == 'A') ]
- print(new_df)
- print('rows number:', new_df.shape[0])
- print('rows number:', len(new_df))
- # --- groups ---
- groups = df.groupby(['type', 'rating'])
- for values, data in groups:
- print('---')
- if values == ('coupe', 'A'):
- print('*** My Favorite ***')
- print('values:', values)
- print('data:\n', data)
- print('rows:', len(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement