Data Visualization Fundamentals for Python Project: Airline Analysis

I am doing the Airline Analysis project as listed in the title. Here is the link to the project.

I am trying to do task 5, where it asks about the relationship between coach price and various inflight features. After a bit of thinking (and some documentation reading to find that Seaborn changed the means of norming a histogram), I was able to produce histograms to answer that question in the form of this code (just in the case of the inflight meals, though I did the other two as well:

sns.histplot(flight.coach_price[flight.inflight_meal == 'Yes'], alpha = 0.5, color = 'green', stat = 'probability')
sns.histplot(flight.coach_price[flight.inflight_meal == 'No'], alpha = 0.5, color = 'red', stat = 'probability')

However, looking at the hint for that task, it recommended using the hue parameter for sns.histplot(). I tried the following:

sns.histplot(flight.coach_price, hue = flight.inflight_meal, alpha = 0.5, color = 'green', stat = 'probability')

but it raised the error: “ValueError: The following variable cannot be assigned with wide-form data: hue

I tried looking at the documentation for histplot to get some insight into how to use the hue parameter, but it did not prove helpful to me. Could someone here help?

I decided to move on to the rest of the tasks, and I got to task 7, which asks to look at the relationship between coach and first class flights across weekend or non-weekends. This is one where I would certainly need to use the hue parameter, and I wrote the following code:

sns.scatterplot(x = 'coach_price', y = 'firstclass_price', hue = 'weekend', data = flight)

but got the following error: “ValueError: not enough values to unpack (expected 2, got 1)”

I’m honestly not sure what to make of this.

did you google the error message by any chance? What were the results?

did you use a subset of the flight data?

In re step 5, I don’t think you need to use the stat= parameter(?)

I had this code:

sns.histplot(flight, x = "coach_price", hue = flight.inflight_meal)

(the hue= parameter will automatically divide data into “yes” and “no” for inflight_meal)

I’m sorry, I would offer more assistance…but, my plots keep disappearing from the LE and CC keeps disconnecting. (I’m using Chrome & getting annoyed :upside_down_face:)

I hadn’t googled the error before. Doing so now suggests a mismatch between the number of arguments expected and received. Which the only way I can interpret that it’s attempting to hue on the weekend column and there’s only 1 value in the column, but that’s simply not the case, which is why I’m at a loss.

As for the stat= probabilityparameter, that’s apparently how sns.histplot norms the data (equivalent to normed = True for plt.hist). Though having now changed my code to yours, it doesn’t seem to do anything when hue’ing, so I’ve removed it.

Thanks for the code though! I guess when hue’ing you need to put the full data set in the data parameter, and then specify what the x and hue are after that. Good to know.

facing the same issue . How did you get through it in scatterplot?

task 7 hue parameter is raising value error