FAQ: Project: Board Slides for FoodWheel - Orders Over Time

This community-built FAQ covers the “Orders Over Time” exercise from the lesson “Project: Board Slides for FoodWheel”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science

FAQs on the exercise Orders Over Time

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hi. I am confused about when we need to use a lambda function. I became confused on Step 3 of this exercise after viewing the hint, which didn’t include the lambda function. I tried to do:

orders[‘month’] = orders.date.split(’-’)[0]

When that didn’t work, I tried variations of:

orders[‘month’] = orders.apply(orders.date.split(’-’)[0])

I finally requested the solution and saw that a lambda function was required. Is there any other way to solve this without a lambda function? If not, what is a good way to determine when lambda functions will be needed? I have struggled with this throughout the lessons. Thank you.

3 Likes

Me too. I’m also confused about when to use lambda. The hints could be better. So could the replies on these forums. I see you asked a month ago already.

This is what worked for me

orders['month'] = orders.apply(lambda x: x['date'].split('-')[0],axis=1)

One needs lambda for more complicated operations using python. I wrote this as a separate function to start with then integrated it into the single line of code. The "axis=1’ makes the code work along the row instead of the column

5 Likes

In this lesson you can find answer https://www.codecademy.com/courses/practical-data-cleaning/lessons/pandas-data-cleaning/exercises/splitting-char?action=resume_content_item

In the Data Science carrer path, the lesson you are refering to is latter than when the question is asked in the Food Wheel project

2 Likes

As I continue to do the Data Science career path, not only do the questions become more vague but also the answers to the lessons contain things that were NEVER in what the lessons taught.

If anyone could explain to me the use of the “.reset_index()” as I thought it was only used when dealing with a dataframe ( I know we are dealing with them here but I thought it was only used to change a series into a DF but maybe I don’t have my definition of “series” correct)

3 Likes

@tlspurlin, I started reporting content bugs on directly in the help section of the lesson content. Maybe it will help Codecademy pinpoint the issue ?

The following works, is simpler than lawburr’s answer, and is accepted by the code parser:

orders['month'] = orders.date.apply(lambda x : x.split('-')[0])

Unfortunately, the following is technically correct but NOT allowed by the code parser. Codecademy should use their coding skills (?) to write a code parser that does not reject valid code:

orders['month'] = pd.DatetimeIndex(orders['date']).month
3 Likes

Is it just me or for the last task is it worded confusingly?

Calculate the standard deviation for the average price of orders for each month using std. Save this to std_order.

They say average price so I assumed they would want us to do something like
std_orders = avg_orders.price.std()
but actually they meant find the standard deviation of the prices from the original table? Wording really threw me off.

2 Likes

I was confused at the same point, but it is also suggested that the purpose is to add error bars to the bar chart, so I think it is possible to guess what they request.

thanks for the answer, I have another doubt… is this correct? orders[‘month’] = orders[‘date’].apply(lambda x : x.split(’-’)[0]), what woud happens if the date column were something like: ‘actual date’

Hello, Can anyone help me with this?
Why this doesn’t work?
orders[‘month’] = orders.date.str.split(’-’)[0]
and the result of this exercise says that we have to use a lambda function

Here are two ways to work on this, I believe there are more ways, this is why it’s interesting.
**Method 1:
orders = pd.read_csv(“orders.csv”, parse_dates=[“date”])
orders[“month”] = orders.date.dt.strftime("%m")

**Method 2:
orders = pd.read_csv(“orders.csv”)
orders.date.apply(lambda i: i.split(’-’)[0])