<jupyter_start><jupyter_text>Other Useful MethodsBefore we cover the more 'complex' methods, there are several more fairly simple yet powerful methods that you should be aware of as the y are used very frequently.* `count`, `describe`, `rank`, `nunique`, `sort_values`, `sort_index`, `dropna`* `idxmin`, `idxmax`, `sample`, `replace`, `isin` Objectives* Look at docstrings of methods* Know the possible values of the parameters* Method chaining* Tricks to get the documentation when method chaining<jupyter_code>import pandas as pd
pd.options.display.max_columns = 50
college = pd.read_csv('data/college.csv', index_col='INSTNM')
college.head()<jupyter_output><empty_output><jupyter_text>`count`Counts the number of non-missing values<jupyter_code>college.count()<jupyter_output><empty_output><jupyter_text>`describe`Provides summary statistics for each column. Defaults to just numeric<jupyter_code>college.describe().T
# can choose data type(s)
college.describe(include='object')<jupyter_output><empty_output><jupyter_text>sort_values by one or more columns<jupyter_code># ascending
college.sort_values('UGDS').head()
# descending
college.sort_values('UGDS', ascending=False).head()
# use a list to sort multiple columns
college.sort_values(['STABBR', 'UGDS']).head()
# use a list to sort multiple columns with one ascending the other descending
college.sort_values(['STABBR', 'UGDS'], ascending=[True, False]).head()<jupyter_output><empty_output><jupyter_text>Chaining methods with dropna, rank and sort_values<jupyter_code>college['SATMTMID'].dropna().rank(ascending=False).sort_values().head(20)
college['SATMTMID'].dropna() \
                   .rank(ascending=False) \
                   .sort_values() \
                   .head(20)
# sort by the values in the index
college.sort_index().head()
# Find the school with the minimum for each column
college.select_dtypes('number').idxmax()<jupyter_output><empty_output><jupyter_text>take a random sample of your data<jupyter_code>college.sample(n=8)<jupyter_output><empty_output><jupyter_text>Your Turn  Problem 1How many unique state abbreviations are there?<jupyter_code>college['STABBR'].nunique()<jupyter_output><empty_output><jupyter_text>Problem 2What school has the largest population in Texas?<jupyter_code>tx_coll=college['STABBR']==('TX')

college[tx_coll].sort_values(['UGDS'],ascending=False).head(1)<jupyter_output><empty_output><jupyter_text>Problem 3Replace all the 0's with 1's<jupyter_code>college['HBCU'].replace(0,1).head()<jupyter_output><empty_output><jupyter_text>Solutions  Problem 1How many unique state abbreviations are there?<jupyter_code>college['STABBR'].nunique()<jupyter_output><empty_output><jupyter_text>Problem 2What school has the largest population in Texas?<jupyter_code>in_texas = college['STABBR'] == 'TX'
tx_schools = college[in_texas]
tx_schools.sort_values('UGDS', ascending=False).head()
# even better
college.loc[college['STABBR'] == 'TX', 'UGDS'].sort_values(ascending=False).head()<jupyter_output><empty_output><jupyter_text>Problem 3Replace all the 0's with 1's<jupyter_code>college.replace(0, 1).head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12854864433811802, 'fraction_numerical': 0.007017543859649123, 'mean_word_length': 7.98567335243553, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '235971', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1034, 'n_words': 222, 'path': '5. Other Useful Methods.ipynb', 'repo_name': 'jsd784/Jasvir-Intro-Data-Science-Python-master', 'size': '3135'}