Question

You will create a new project. Type in the following program and run it to produce...

You will create a new project. Type in the following program and run it to produce the output for the program. Good practice in writing a program in any language, including Python, is to add comments for each line and state clearly what is the program input and output. Your program must include comments, so a reader will know exactly what you are trying to do in each line of code and allow for easy maintenance. Beginning a line with a hash (#) character results in a single line comment and automatically terminated by the end of line. Comments that span multiple lines can be created by adding a triple quote (""") on each end of the block of comments. You will use PyCharm Edu to run the following Python program. The process must finish with exit code 0.

#BEGIN

""" Program Begin HERE
Some data Exploration using Python. Assuming that all the needed packages
are already install for your IDE to find them.
"""
#############################################################
#Program name - Data Exploration
#input - NONE
#output - Some Exploration statistics
###############################################################
import pandas as pd

# Create data_frame of array values
df = pd.DataFrame({
    'name':['matt','lisa','richard','john','Julia','jane','marlon'],
    'age':[23,78,22,19,45,33,20],
    'gender':['M','F','M','M','M','F','M'],
    'state':['DC','CO','DE','VA','MD','DE','NY'],
    'years_of_service':[10,0,2,0,2,1,5],
    'iq':[300,100,110,200,300,10,40]
})
########################################################
# BEGIN extract a 25% sample of data
########################################################
rows = df.sample(frac =.25)
# validate first to check if sample is 0.25 times data or not
if (0.25*(len(df))== len(rows)):
    print(len(df), len(rows))

# Display Sample Percentage
print 'sample of 25%',rows

#END extract a 25% sample of data
############################################################
# BEGIN Split categorical variables by gender, Sum, Mean, count,
# and describe on the data
############################################################

#Categorical Variables splitting
groupby_gender = df.groupby('gender')
for gender, value in groupby_gender['iq']:
    print((gender, value.mean()))

# Find the Summation of all ages in the data
SumofAge=df['age'].sum()
print 'Sum of Ages', SumofAge

MeanAge = df['age'].mean()
print 'Average Ages', MeanAge
# Find the mean of all columns
print ('Means of each column', df.mean(axis=0))
# Describe the Data
print df['iq'].describe()

#END

I keep getting an exit code of 1 saying line 32 is wrong! Help?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python modified code:

#BEGIN

""" Program Begin HERE

Some data Exploration using Python. Assuming that all the needed packages

are already install for your IDE to find them.

"""

#############################################################

#Program name - Data Exploration

#input - NONE

#output - Some Exploration statistics

###############################################################

import pandas as pd

# Create data_frame of array values

df = pd.DataFrame({

'name':['matt','lisa','richard','john','Julia','jane','marlon'],

'age':[23,78,22,19,45,33,20],

'gender':['M','F','M','M','M','F','M'],

'state':['DC','CO','DE','VA','MD','DE','NY'],

'years_of_service':[10,0,2,0,2,1,5],

'iq':[300,100,110,200,300,10,40]

})

########################################################

# BEGIN extract a 25% of sample data

########################################################

rows = df.sample(frac =.25)

# validate first to check if sample is 0.25 times data or not

if (0.25*(len(df))== len(rows)):

print(len(df), len(rows))

# Display Sample Percentage

print ("Sample of 25%\n")

print(rows)

#END extract a 25% sample of data

############################################################

# BEGIN Split categorical variables by gender, Sum, Mean, count,

# and describe on the data

############################################################

#Categorical Variables splitting

groupby_gender = df.groupby('gender') #Grouping dataframe by 'gender'

for gender, value in groupby_gender['iq']:

print((gender, value.mean())) #print gender,corresponding mean

# Find the Summation of all ages in the data

SumofAge=df['age'].sum()

print ('Sum of Ages '+ str(SumofAge))

MeanAge = df['age'].mean()

print ('Average Ages ', str(MeanAge))

# Find the mean of all columns

print ('Means of each column ',str(df.mean(axis=0)))

# Describe the Data

print (df['iq'].describe())

#END


Python code Implementation:

OUTPUT:

NOTE:

# Beware of the indentation while copying the code into editor

# Any clarifications regarding this question can be asked in the comments section

Add a comment
Know the answer?
Add Answer to:
You will create a new project. Type in the following program and run it to produce...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Error: Writing a program to complete the following: Prompt the user for the name of...

    Python Error: Writing a program to complete the following: Prompt the user for the name of an input file. Open that file for input. (reading) Read the file using a "for line in a file" loop For each line,  o print the line and compute and print the average word length for that line. Close the input file Sample output: MY CODE IS WRONG AND NEED HELP CORRECTING IT!!! ------------------------------------------------------------------------------------------------------------------------ DESIRED OUTPUT: Enter input file name: Seasons.txt Thirty days hath September...

  • Write an assembly language program to do the following, and run it and test it on...

    Write an assembly language program to do the following, and run it and test it on the lab simulator: Read in integers until a zero is read in. Keep a total of both the quantity and the sum of the negative integers and the positive integers. Once a zero is read in (signifying the end of the input) then: • If there were more positive than negative integers, or an equal number, print out a 0 and the sum of...

  • IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in th...

    IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in the table, and 4 columns, followed by  averages. Calculate the ideal age of a spouse. Enter either m or f from the keyboard in lower case. You may use string data for the gender. Convert the gender to upper case Enter an age from the keyboard, probably an integer You will need prompts telling the...

  • IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse,...

    IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in the table, and 4 columns, followed by  averages. Calculate the ideal age of a spouse. Enter either m or f from the keyboard in lower case. You may use string data for the gender. Convert the gender to upper case Enter an age from the keyboard, probably an integer You will need prompts telling the user...

  • CISC 1115 Assignment 6 Write a complete program, including javadoc comments, to process voter statistics Input...

    CISC 1115 Assignment 6 Write a complete program, including javadoc comments, to process voter statistics Input to Program: A file containing lines of data, such that each line has 2 integers on it The first integer represents a zip code (in Brooklyn or the Bronx), and the second represents the number of voters in that zip code. Output: All output may be displayed to the screen. In main: 1. Your program will read in all of the data in the...

  • Write, save, and run a Python program that will do the following when run: Let’s consider...

    Write, save, and run a Python program that will do the following when run: Let’s consider the following assignment: a = 1 * 2 + 38 / 8 You want to change the precedence of the operators so that the addition operations are executed first. How would you re-write the assignment? Write a print statement to show the output. Let’s consider the following assignments: x = 'z' y= ['x', 'z', 'q'] Now, apparently x is a member of y. Write...

  • You previously wrote a program that calculates and displays: Miles driven Miles per gallon Kilometers driven...

    You previously wrote a program that calculates and displays: Miles driven Miles per gallon Kilometers driven Liters of fuel consumed Kilometers per liter Messages commenting on a vehicle's fuel efficiency And also validates input Now we'll make a somewhat major change. We'll remove the code for obtaining input from a user and replace it with hardcoded data stored in lists. Because the data is hardcoded, the program will no longer need the code for validating input. So, you may remove...

  • The Program (Java) You will create a pet database program with the following operations incrementally as...

    The Program (Java) You will create a pet database program with the following operations incrementally as describe in the Milestones section. You are not required to save the pet data into a file. You must use appropriate design and make use of Object-Oriented Design. See milestones. • Add pets o Let the user add as many pets as they want. A pet is entered as a single line consisting of a name and an integer which represents the age of...

  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

  • MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for...

    MEDIA INHERITANCE - C++ You will create an inheritance set of classes. Use proper rules for data types, class definitions, and inheritance (check input/output of data below). You will create a super media class that will define a general form of media. A media properties will consist of the name and price. The media should be able to construct itself out of the arguments sent to it, virtually print both data fields labeled (price to two decimal places) and overload...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT