Question

Using Python (pandas as pd) I am trying to use the split, apply, combine method but...

Using Python (pandas as pd) I am trying to use the split, apply, combine method but am getting an "invalid syntax" error at the end of the line that says "for days_name, days_df in grouped_by_day" I declared grouped_by_day in the split function but did not get any errors so I am not sure what happened or how to fix it. Below is a copy of the split, apply, combine section of my code.

mean_data_ser = pd.Series()

#split

grouped_by_day= days_df.groupby("Day of Week")

#apply

for days_name, days_df in grouped_by_day (This is the line where I get the error)

mean_functionality= days_df["Day of Week"].mean()

print (mean_functionality)

#combine

mean_functionality_ser[str(days_name)]= mean_functionality

print mean_functionality_ser

Homework Answers

Answer #1

In the given code there are few errors.

for days_name, days_df in grouped_by_day you have to put colon at the end of this statement.

mean_functionality= days_df["Day of Week"].mean() this line is indented wrongly so move this line.and

print mean_functionality_ser ​​​​​​missing paranthesis

The print statement must have paranthesis to display output.

The below code fix these three errors.

Code:

mean_data_ser = pd.Series()

#split

grouped_by_day= days_df.groupby("Day of Week")

#apply

for days_name, days_df in grouped_by_day: #(This is the line where I get the error)

mean_functionality= days_df["Day of Week"].mean()

print (mean_functionality)

#combine

mean_functionality_ser[str(days_name)]= mean_functionality

print (mean_functionality_ser)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I am trying to print an essay in my python code but the words keep getting...
I am trying to print an essay in my python code but the words keep getting cut over two lines. How can i fix this using python code so that it is formatted nicely? thanks
In Python (using pandas and numpy) I am trying to clean CSV data so it adheres...
In Python (using pandas and numpy) I am trying to clean CSV data so it adheres to a strict coding system instead of free response. More specifically, how would I code a simple rule based system to handle the various spellings and word choices that represent the following statuses: Never married Divorced Married Widowed Separated
In python: I am trying to construct a list using enumerate and takewhile from a Fibonaci...
In python: I am trying to construct a list using enumerate and takewhile from a Fibonaci generator. So far the code I have is the following: def fibonacci(): (a, b) = (0, 1) while True: yield a (a, b) = (b, a + b) def createlist(n, fib): return [elem for (i, elem) in enumerate(takewhile(lambda x: x < n, fib)) if i < n] I only get half the list when I do: print(createlist(n, fibonacci())) Output: [0, 1, 1, 2, 3,...
I am working on exercise 5.30 from Introduction to Computing using python (Author: Perkovic). I was...
I am working on exercise 5.30 from Introduction to Computing using python (Author: Perkovic). I was looking at the solution and was able to understand what to do. However, when I implement the temp function as indicated, I keep getting this error "ValueError: the first two maketrans arguments must have equal length". However, it seems my two arguments are equal length, so I'm not sure what I am doing wrong! print('Exercise 5.30') def many(file): infile = open(file) content = infile.read()...
No matter what I do I cannot get this code to compile. I am using Visual...
No matter what I do I cannot get this code to compile. I am using Visual Studio 2015. Please help me because I must be doing something wrong. Here is the code just get it to compile please. Please provide a screenshot of the compiled code because I keep getting responses with just code and it still has errors when I copy it into VS 2015: #include <iostream> #include <conio.h> #include <stdio.h> #include <vector> using namespace std; class addressbook {...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...