SSCC - Social Science Computing Cooperative Supporting Statistical Analysis for Research

3.3 Relationships between continuous and categorical variables

These exercises use the Mroz.csv data set that was imported in the prior section.

  1. Import the Mroz.csv data set.

    from pathlib import Path
    import pandas as pd
    import plotnine as p9
    mroz_path = Path('..') / 'datasets' / 'Mroz.csv'
    mroz = pd.read_csv(mroz_path)
    
    print(mroz.dtypes)
    Unnamed: 0      int64
    lfp            object
    k5              int64
    k618            int64
    age             int64
    wc             object
    hc             object
    lwg           float64
    inc           float64
    dtype: object
  2. Create a boxplot for lwg for women who attended college and women who did not.

    print(
        p9.ggplot(mroz, p9.aes(x='wc', y='lwg')) + 
        p9.geom_boxplot() +
        p9.theme_bw())
    <ggplot: (143590674959)>

  3. Create a boxplot for lwg for men who attended college and men who did not.

    print(
        p9.ggplot(mroz, p9.aes(x='hc', y='lwg')) + 
        p9.geom_boxplot() +
        p9.theme_bw())
    <ggplot: (143590107859)>