Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Importing and Parsing
- >>>Import pandas as pd
- df = pd.read_csv('file_name.csv')
- #Checking the mean of all attributes (columns) in a data set
- df.mean()
- #Finding the mean of attributes when holding one attribute as an index
- _I.e: Here, I want to find the mean of all the other attributes with each occurence of the petal length attribute._
- >>>df.groupby('petal_length').mean()
- #We can even add multiple entries to hold as an index
- >>>df.groupby(['petal_length', 'color']).mean()
- #If we don't want the attributes we choose to be made as an index, we can use as_index=false:
- >>>df.groupby(['petal_length', 'color'], as_index=False).mean()
- #And finally, if we are interested in only one attribute (column) we can index it as follows:
- >>>df.groupby(['petal_length', 'color'], as_index=False)['petal_width'].mean()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement