<jupyter_start><jupyter_text>Data Visualization with Modern Data Science> Analyzing Data with TableauKuo, Yao-Jen  TL; DR> In this lecture, we will release Tableau's plotting capability and use calculated fields if current fields are unable to answer our questions.  Creating More Plots with Tableau  In the last chapter, we've created- Scatter to explore correlations- Histogram to explore distributions- Bar to explore rankings- Line to explore trends- Box to explore distributions based on categories  In fact, we might confidently say that MOST(probably 87%?) of the exploratory analysis are done  However, there are still plenty of plots that is often used for certain purposes  Area works like line, but it involves the information of combinations  Using area to explore trends and combination at the same time- Create another worksheet- Change `Year` data type to `Date`- Dragging `Year` onto Columns- Dragging `Pop` onto Rows- Dragging `Continent` to Color- Click Show Me then click **area charts(continuous)**  Done with a simple area!![Imgur](https://i.imgur.com/TZdYCsJ.png?1)  What are those (discrete), anyway?- lines(discrete)- area charts(discrete)  These are designed for the date variables with YYYY-MM-DD information  Take area charts(discrete) for a quick exampleLet's get a new data source.[Right click to download](https://python4ds.s3-ap-northeast-1.amazonaws.com/fang_volume.csv)  Use Visual Studio Code to open `fang_volume.csv`![Imgur](https://i.imgur.com/NVnabMr.png?1)  Adding a new data source to our workbook![Imgur](https://i.imgur.com/gPwnndk.png?1)  Area(discrete) to explore trends and combination at the same time- Create another worksheet- Dragging `Date` onto Columns- Dragging `Volume` onto Rows- Dragging `Symbol` to Color- Click Show Me then click **area charts(discrete)**- Drill down `Date` variable  Done with a simple area(discrete)!![Imgur](https://i.imgur.com/lCoFH8c.png?1)  Bullet works like bar, but it involves comparison between 2 measures  Get a summarized version of gapminder[Right click to download](https://python4ds.s3-ap-northeast-1.amazonaws.com/gapminder_pop_by_cont_year.csv)  Use Visual Studio Code to open `gapminder_pop_by_cont_year.csv`![Imgur](https://i.imgur.com/7pDJCSo.png?1)  Adding a new data source to our workbook![Imgur](https://i.imgur.com/gPwnndk.png?1)  Check if the first row is treated as field names![Imgur](https://i.imgur.com/18vMAEb.png)  Using bullet to explore the comparison between 2 measures- Create another worksheet- Dragging both `2002` and `2007` onto Columns- Dragging `Continent` onto Rows- Click Show Me then click **bullet graph**  Done with a simple bullet!![Imgur](https://i.imgur.com/uwtM65F.png)  To swap the two measures, right-click the axis and select Swap Reference Line Fields![Imgur](https://i.imgur.com/JVUTPy9.png?1)  Circle views work like box  Using circle views to explore distributions based on categories- Create another worksheet- Dragging `Continent` and `Country` onto Columns- Dragging `Gdp percap` onto Rows- Replacing Measure with Dimension- Dragging `Continent` onto Color  Done with a simple circle views!![Imgur](https://i.imgur.com/5FaTQCN.png?1)  Dual combination integrates a bar and a line with dual axis  Using dual combination to explore trends with 2 measures- Create another worksheet- Dragging `Year` onto Columns- Dragging `Pop` and `Life Exp` onto Rows- Replacing the measure of `SUM(Life Exp)` with `AVG(Life Exp)`- Click Show Me then click **dual combination**- Adjust `SUM(Pop)` with bar, `AVG(Life Exp)` with line  Done with a simple dual combination!![Imgur](https://i.imgur.com/llBcMSU.png?1)  Dual line integrates 2 lines with dual axis  Using dual line to explore trends with 2 measures- Create another worksheet- Dragging `Year` onto Columns- Dragging `Gdp Percap` and `Life Exp` onto Rows- Replacing the measure of `SUM()` with `AVG()`- Click Show Me then click **dual line**  Done with a simple dual line!![Imgur](https://i.imgur.com/oSLjqE9.png?1)  Heat maps works like scatter, but it is used to visualize patterns or trends in dense data with many overlapping marks particularly  Using heat maps to explore correlation and the density of data points- Create another worksheet- Dragging `Gdp Percap` onto Columns- Dragging `Life Exp` onto Rows- Replacing Measure with Dimension- On the Marks card, select Density from the menu- Adjusting Color or Size for your preference  Selecting Density from the menu![Imgur](https://i.imgur.com/EtXdWbw.png?1)  Adjusting Color![Imgur](https://i.imgur.com/SnBhl6m.png?1)  Adjusting Size![Imgur](https://i.imgur.com/FTFWomZ.png)  Done with a simple heat map!![Imgur](https://i.imgur.com/iXEE5rY.png?1)  Highlight tables are similar to heat maps in that they display data in various categories using different colors  Using highlight tables to explore ranking- Create another worksheet- Dragging `Year` onto Columns- Dragging `Continent` and `Country` onto Rows- Dragging `Gdp Percap` onto Color  Done with a simple highlight table!![Imgur](https://i.imgur.com/GUCgK3C.png?1)  Packed bubble works like bar, but it involves a hierarchy feature and shows measure to with the size of the bubbles  Using packed bubble to explore ranking- Create another worksheet- Creating a hierarchy variable with `Continent` and `Country`- Dragging `Continent, Country` onto Columns- Dragging `Pop` onto Rows- Click Show Me then click **packed bubbles**- Dragging `Year` onto Pages- Drilling down by clicking the plus sign next to `Continent`  Creating a hierarchy variable with `Continent` and `Country`![Imgur](https://i.imgur.com/oT4TfqP.png)  Drilling down by clicking the plus sign next to Continent![Imgur](https://i.imgur.com/SEWd75R.png?1)  Done with a simple packed bubble!![Imgur](https://i.imgur.com/zFjEnKB.png?1)  Pie works like bar, but it shows proportions at the same time  Using pie to explore ranking and proportions- Create another worksheet- Dragging `Continent` onto Columns- Dragging `Pop` onto Rows- Click Show Me then click **pie charts**  Done with a simple pie!![Imgur](https://i.imgur.com/3GWBMKS.png)  Side-by-side bar works exactly like bar, but it involves comparison with another dimension  Using side-by-side bar to explore ranking and comparison- Create another worksheet- Dragging `Year` and `Continent` onto Columns- Dragging `Pop` onto Rows- Dragging `Continent` onto Color- Click Show Me then click **side-by-side bars**  Done with a simple side-by-side bar!![Imgur](https://i.imgur.com/roRhffi.png?1)  Side-by-side circle views work exactly like circle views, but it involves comparison with another dimension  Using side-by-side circle views to explore distributions based on categories- Create another worksheet- Dragging `Year` and `Continent` onto Columns- Dragging `Gdp Percap` onto Rows- Replacing Measure with Dimension- Dragging `Continent` onto Color- Click Show Me then click **side-by-side circles**  Done with a simple side-by-side circle!![Imgur](https://i.imgur.com/oScaVFh.png?1)  Stacked bar works exactly like bar, but it involves the contribution of individual elements  Using stacked bar to explore ranking and composition- Create another worksheet- Dragging `Year` and `Continent` onto Columns- Dragging `Pop` onto Rows- Click Show Me then click **stacked bars**  Done with a simple stacked bar!![Imgur](https://i.imgur.com/qKbRjjc.png?1)  Text tables display values as numbers in a table(also called cross-tabs or pivot tables)  Let's get a new data source.[Right click to download](https://python4ds.s3-ap-northeast-1.amazonaws.com/03-18-2020.csv)  Use Visual Studio Code to open `03-18-2020.csv`![Imgur](https://i.imgur.com/LN37FFp.png?1)  Adding a new data source to our workbook![Imgur](https://i.imgur.com/gPwnndk.png?1)  Using text tables to explore summarized numbers in a table- Create another worksheet- Dragging `Confirmed`, `Deaths`, and `Recovered` onto Columns- Dragging `Country/Region` and `Province/State` onto Rows- Click Show Me then click **text table**  Done with a simple text table!![Imgur](https://i.imgur.com/ESmuh0L.png?1)  Treemap works like exactly like stacked bar  Using treemap to explore ranking and composition- Create another worksheet- Dragging `Confirmed` onto Columns- Dragging the default hierarchy variable `Country/Region, Province/State` onto Rows- Click Show Me then click **treemaps**- Drilling down by clicking the plus sign next to `Country/Region, Province/State`  Done with a simple treemap!![Imgur](https://i.imgur.com/cp5MBtp.png?1)  Symbol map works like a text table, but it shows values on a geographical map  Using symbol map to explore summarized numbers on a geographical map- Create another worksheet- Double-click `Province/State`- Dragging `Confirmed` onto Size- Drilling down and fold-up by clicking the plus sign next to `Country/Region, Province/State`  Done with a simple symbol map!![Imgur](https://i.imgur.com/xf4FBtU.png?1)  Filled map works like symbol map, but it uses a color gradient rather than size to represent the valueFilled map is more commonly referenced as a polygon map.  Using filled map to explore summarized numbers on a geographical map- Create another worksheet- Double-click `Province/State`- Click the Marks drop-down and select Map- Dragging `Confirmed` onto Color- Drilling down and fold-up by clicking the plus sign next to `Country/Region, Province/State`  Done with a simple filled map!![Imgur](https://i.imgur.com/UpQ3wde.png?1)  A preview of the Python code we will write in near future<jupyter_code>from datetime import date, timedelta
import pandas as pd

# get daily covid-19 stats
delta = timedelta(days=-1)
yesterday = date.today() + delta
# modify date format
yesterday_str = yesterday.strftime("%m-%d-%Y")
csv_name = yesterday_str + ".csv"
csv_url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/{}".format(csv_name)
covid19_daily = pd.read_csv(csv_url)
# Observe NaN in original data
covid19_daily.head()
# Replace NaN with Country/Region
column_to_replace = "Province/State"
province_state = [cr if pd.isna(ps) else ps for ps, cr in zip(covid19_daily["Province/State"].values, covid19_daily["Country/Region"].values)]
covid19_daily = covid19_daily.drop(column_to_replace, axis=1)
covid19_daily.insert(0, column_to_replace, province_state)
covid19_daily.to_csv(csv_name, index=False)
# Imputed data
covid19_daily.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09246837868915293, 'fraction_numerical': 0.011115369873514757, 'mean_word_length': 5.050434782608695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 34, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '511247', 'license': 'MIT', 'n_tokens_mistral': 3162, 'n_tokens_neox': 3012, 'n_words': 1250, 'path': '02-analyzing-data-with-tableau.ipynb', 'repo_name': 'yaojenkuo/viz_and_modern_ds_2020_spring', 'size': '10436'}