<jupyter_start><jupyter_text>Introduction to pdvegaFull article at [pbpython.com](http://pbpython.com/pdvega.html)<jupyter_code>import pandas as pd
import pdvega
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Read in the FiveThirtyEight data on candy<jupyter_code>df = pd.read_csv("https://github.com/fivethirtyeight/data/blob/master/candy-power-ranking/candy-data.csv?raw=True")
# Clean up broken apostrophe
df['competitorname'].replace(regex=True,inplace=True,to_replace=r'Õ',value=r"'")
df.head()<jupyter_output><empty_output><jupyter_text>Try a pandas plot first<jupyter_code>df["winpercent"].plot.hist(figsize=(10,6))<jupyter_output><empty_output><jupyter_text>Try the same thing using pdvega<jupyter_code>df["winpercent"].vgplot.hist()<jupyter_output><empty_output><jupyter_text>KDE plots work as expected<jupyter_code>df["sugarpercent"].vgplot.kde()<jupyter_output>/home/lhphong/anaconda3/lib/python3.7/site-packages/pdvega/_core.py:79: FutureWarning: A future version of pandas will default to `skipna=True`. To silence this warning, pass `skipna=True|False` explicitly.
  "type": infer_vegalite_type(df[x], ordinal_threshold=0)
/home/lhphong/anaconda3/lib/python3.7/site-packages/pdvega/_core.py:83: FutureWarning: A future version of pandas will default to `skipna=True`. To silence this warning, pass `skipna=True|False` explicitly.
  "type": infer_vegalite_type(df[y], ordinal_threshold=0)<jupyter_text>We can look at the sugar and price percentile distributions<jupyter_code>df["sugarpercent"].vgplot.hist()
df["pricepercent"].vgplot.hist()
df[["sugarpercent", "pricepercent"]].vgplot.hist()<jupyter_output><empty_output><jupyter_text>Compare it to the pure pandas example<jupyter_code>df[["sugarpercent", "pricepercent"]].plot.hist(alpha=0.5, figsize=(10,5))<jupyter_output><empty_output><jupyter_text>Let's try some scatter plots<jupyter_code>df.vgplot.scatter(x='pricepercent', y='sugarpercent')
df.vgplot.scatter(x='winpercent', y='sugarpercent')<jupyter_output><empty_output><jupyter_text>The pandas version does not look as nice<jupyter_code>df.plot.scatter(x='winpercent', y='sugarpercent', c='bar')<jupyter_output><empty_output><jupyter_text>pdvega suppports encoding the size and color based on values in columns of the dataframe<jupyter_code>df.vgplot.scatter(x='winpercent', y='sugarpercent', s='pricepercent', c='bar')<jupyter_output><empty_output><jupyter_text>The scatter matrix is really helpful<jupyter_code>pdvega.scatter_matrix(df[["sugarpercent", "winpercent", "pricepercent"]], "winpercent")<jupyter_output><empty_output><jupyter_text>Here's a simple bar chart.Unfortunately I could not figure out how to sort by the winpercent<jupyter_code>df.sort_values(by=['winpercent'], ascending=False).head(10)
df.sort_values(by=['winpercent'], ascending=False).head(15).plot.barh(x='competitorname', y='winpercent')
df.sort_values(by=['winpercent'], ascending=False).head(15).vgplot.barh(x='competitorname', y='winpercent')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14505347593582887, 'fraction_numerical': 0.008689839572192513, 'mean_word_length': 10.876984126984127, 'pattern_counts': {'":': 2, '<': 48, '<?xml version=': 0, '>': 48, 'https://': 1, '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': '346226', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1068, 'n_words': 163, 'path': 'notebooks/08_Pdvega.ipynb', 'repo_name': 'Gio1609/pandas_practical_busines', 'size': '2992'}