<jupyter_start><jupyter_text>5 new changes in pandas you need to know about ([video](https://www.youtube.com/watch?v=te5JrSCW-LY&list=PL5-da3qGB5ICCsgW1MxlZ0Hq8LL5U3u9y&index=33))- [My pandas video series (30 videos)](http://www.dataschool.io/easier-data-analysis-with-pandas/)- [GitHub repository](https://github.com/justmarkham/pandas-videos)- [pandas release notes](http://pandas.pydata.org/pandas-docs/stable/whatsnew.html)<jupyter_code>import pandas as pd
pd.__version__<jupyter_output><empty_output><jupyter_text>1. `ix` has been deprecated*New in 0.20.0*<jupyter_code># read the drinks dataset into a DataFrame
drinks = pd.read_csv('http://bit.ly/drinksbycountry', index_col='country')
drinks.head()
# loc accesses by label
drinks.loc['Angola', 'spirit_servings']
# iloc accesses by position
drinks.iloc[4, 1]
# ix accesses by label OR position (newly deprecated)
drinks.ix['Angola', 1]
# alternative: use loc
drinks.loc['Angola', drinks.columns[1]]
# alternative: use iloc
drinks.iloc[drinks.index.get_loc('Angola'), 1]
# ix accesses by label OR position (newly deprecated)
drinks.ix[4, 'spirit_servings']
# alternative: use loc
drinks.loc[drinks.index[4], 'spirit_servings']
# alternative: use iloc
drinks.iloc[4, drinks.columns.get_loc('spirit_servings')]<jupyter_output><empty_output><jupyter_text>- [More information](http://pandas.pydata.org/pandas-docs/stable/indexing.htmlix-indexer-is-deprecated)- [Video: How do I select multiple rows and columns from a pandas DataFrame?](https://www.youtube.com/watch?v=xvpNA7bC8cs&list=PL5-da3qGB5ICCsgW1MxlZ0Hq8LL5U3u9y&index=19)  2. Aliases have been added for `isnull` and `notnull`*New in 0.21.0*<jupyter_code># read the UFO dataset into a DataFrame
ufo = pd.read_csv('http://bit.ly/uforeports')
ufo.head()
# check which values are missing
ufo.isnull().head()
# check which values are not missing
ufo.notnull().head()
# drop rows with missing values
ufo.dropna().head()
# fill in missing values
ufo.fillna(value='UNKNOWN').head()
# new alias for isnull
ufo.isna().head()
# new alias for notnull
ufo.notna().head()<jupyter_output><empty_output><jupyter_text>- [More information](http://pandas.pydata.org/pandas-docs/stable/whatsnew.htmlna-naming-changes)- [Video: How do I handle missing values in pandas?](https://www.youtube.com/watch?v=fCMrO_VzeL8&list=PL5-da3qGB5ICCsgW1MxlZ0Hq8LL5U3u9y&index=16)  3. `drop` now accepts "index" and "columns" keywords*New in 0.21.0*<jupyter_code># read the UFO dataset into a DataFrame
ufo = pd.read_csv('http://bit.ly/uforeports')
ufo.head()
# old way to drop rows: specify labels and axis
ufo.drop([0, 1], axis=0).head()
ufo.drop([0, 1], axis='index').head()
# new way to drop rows: specify index
ufo.drop(index=[0, 1]).head()
# old way to drop columns: specify labels and axis
ufo.drop(['City', 'State'], axis=1).head()
ufo.drop(['City', 'State'], axis='columns').head()
# new way to drop columns: specify columns
ufo.drop(columns=['City', 'State']).head()<jupyter_output><empty_output><jupyter_text>- [More information](http://pandas.pydata.org/pandas-docs/stable/whatsnew.htmldrop-now-also-accepts-index-columns-keywords)- [Video: How do I remove columns from a pandas DataFrame?](https://www.youtube.com/watch?v=gnUKkS964WQ&list=PL5-da3qGB5ICCsgW1MxlZ0Hq8LL5U3u9y&index=6)  4. `rename` and `reindex` now accept "axis" keyword*New in 0.21.0*<jupyter_code># old way to rename columns: specify columns
ufo.rename(columns={'City':'CITY', 'State':'STATE'}).head()
# new way to rename columns: specify mapper and axis
ufo.rename({'City':'CITY', 'State':'STATE'}, axis='columns').head()
# note: mapper can be a function
ufo.rename(str.upper, axis='columns').head()<jupyter_output><empty_output><jupyter_text>- [More information](http://pandas.pydata.org/pandas-docs/stable/whatsnew.htmlrename-reindex-now-also-accept-axis-keyword)- [Video: How do I rename columns in a pandas DataFrame?](https://www.youtube.com/watch?v=0uBirYFhizE&list=PL5-da3qGB5ICCsgW1MxlZ0Hq8LL5U3u9y&index=5)  5. Ordered categories must be specified independent of the data*New in 0.21.0*<jupyter_code># create a small DataFrame
df = pd.DataFrame({'ID':[100, 101, 102, 103],
                   'quality':['good', 'very good', 'good', 'excellent']})
df
# old way to create an ordered category (deprecated)
df.quality.astype('category', categories=['good', 'very good', 'excellent'], ordered=True)
# new way to create an ordered category
from pandas.api.types import CategoricalDtype
quality_cat = CategoricalDtype(['good', 'very good', 'excellent'], ordered=True)
df['quality'] = df.quality.astype(quality_cat)
df.quality<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15583008235804074, 'fraction_numerical': 0.025357607282184655, 'mean_word_length': 6.372204472843451, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '424546', 'license': 'Apache-2.0', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1696, 'n_words': 368, 'path': 'jupyter/pandas-videos/pandas_changes.ipynb', 'repo_name': 'mullenkamp/EcanPythonCourse2019', 'size': '4614'}