0

I am trying to create a diagonal plot in python, I am working off an example that works but I am getting a key error message. The code is the following:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

filename = 'https://library.startlearninglabs.uw.edu/DATASCI410/Datasets/JitteredHeadCount.csv'
headcount_df = pd.read_csv(filename)
headcount_df.describe()

num_cols = ["TablesOcc", "ablesOpen", "HeadCount", "TablesClosed", "DayNumber"] 
sns.pairplot(headcount_df.loc[:, num_cols], hue='DayOfWeek', 
             palette="seismic", diag_kind="kde", 
             size=2).map_upper(sns.kdeplot, cmap="Blues")

I am getting a key error messaging KeyError: 'DayOfWeek'and

KeyError                                  Traceback (most recent call last)

I am not sure why it is not working this time. any help would be appreciated.

2
  • Are you passing the 'DayOfWeek' column to pairplot? Commented Jul 14, 2020 at 1:42
  • Typo too - "ablesOpen" should be "TablesOpen". Commented Jul 14, 2020 at 1:46

1 Answer 1

2

This should work

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

filename = 'https://library.startlearninglabs.uw.edu/DATASCI410/Datasets/JitteredHeadCount.csv'
headcount_df = pd.read_csv(filename)
headcount_df.describe()

sns.pairplot(headcount_df, hue='DayOfWeek', 
             palette="seismic", diag_kind="kde", vars=["TablesOcc", "TablesOpen", "HeadCount", "TablesClosed", "DayNumber"],
             size=2).map_upper(sns.kdeplot, cmap="Blues")
Sign up to request clarification or add additional context in comments.

3 Comments

Do you have much experience with Jupiter Notebook? I am having issues with the code not computing. The code is simple so should only take a few seconds to complete but this is the second time I have had an issue with the code not computing in this book. any ideas why that may be?
It seems like pairplot is just an expensive function and it probably doesn't help that there are 175,000 entries in your csv file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.