Write a class named Person with data attributes for a person’s name, address, and…
- User
Write a class named Person with data attributes for a person’s name, address, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number, and a Boolean data attribute indicating whether the customer wishes to be on a mailing list. Demonstrate an instance of the Customer class in a simple program.
- Assistant
class Person: def init(self, name, address, telephone_number): self.name = name self.address = address self.telephone_number = telephone_number
class Customer(Person): def init(self, name, address, telephone_number, customer_number, wants_mailing_list): super().init(name, address, telephone_number) self.customer_number = customer_number self.wants_mailing_list = wants_mailing_list
Create an instance of the Customer class
customer = Customer("John Doe", "123 Main Street", "555-1234", 12345, True)
Access and print the attributes of the Customer object
print("Customer Name:", customer.name) print("Address:", customer.address) print("Telephone Number:", customer.telephone_number) print("Customer Number:", customer.customer_number) print("Wants Mailing List:", customer.wants_mailing_list)
- User
use a boolean data attribute to write this code again
- Assistant
class Person: def init(self, name, address, telephone_number): self.name = name self.address = address self.telephone_number = telephone_number
class Customer(Person): def init(self, name, address, telephone_number, customer_number, wants_mailing_list=False): super().init(name, address, telephone_number) self.customer_number = customer_number self.wants_mailing_list = wants_mailing_list
Create an instance of the Customer class
customer = Customer("John Doe", "123 Main Street", "555-1234", 12345, True)
Access and print the attributes of the Customer object
print("Customer Name:", customer.name) print("Address:", customer.address) print("Telephone Number:", customer.telephone_number) print("Customer Number:", customer.customer_number) print("Wants Mailing List:", customer.wants_mailing_list)
- User
fips_to_state = { "1": 'AL', "2": "AK", "4": 'AR','5': "AR", "6": "CA", "8": "CO", "9": "CT", "10": "DE", "11": "DC", "12": "FL", "13": "GA", "15": "HI", "16": "ID", "17": "IL", "18": "IN", "19": "IA", "20": "KS", "21": "KY", "22": "LA", "23": "ME", "24": "MD", "25": "MA", "26": "MI", "27": "MN", "28": "MS", "29": "MO", "30": "MT", "31": "NE", "32": "NV", "33": "NH", "34": "NJ", "35": "NM", "36": "NY", "37": "NC", "38": "ND", "39": "OH", "40": "OK", "41": "OR", "42": "PA", "44": "RI", "45": "SC", "46": "SD", "47": "TN", "48": "TX", "49": "UT", "50": "VT", "51": "VA", "53": "WA", "54": "WV", "55": "WI", "56": "WY", "72": "PR"}
- Assistant
The given code is a dictionary mapping Federal Information Processing Standards (FIPS) codes to their respective state abbreviations. Each key-value pair in the dictionary represents a FIPS code and its corresponding state abbreviation.
Here is an example usage of the
fips_to_statedictionary:# Accessing state abbreviation for a FIPS code fips_code = "13" state_abbreviation = fips_to_state[fips_code] print(state_abbreviation) # Output: GA # Adding a new FIPS code to the dictionary fips_to_state["60"] = "AS" # AS represents American Samoa - User
Load the population estimates file into a dataframe. Specify an absolute path using the Python os library to join filenames, so that anyone who clones your homework repo only needs to update one for all loading to work. Your data only includes fips codes for states. Use the uslibrary to crosswalk fips codes to state abbreviations. Keep only the state abbreviations in your data.
- Assistant
To load the population estimates file into a dataframe and crosswalk FIPS codes to state abbreviations, you can follow the steps below:
- Import the necessary libraries:
import pandas as pd import os- Specify the absolute path for the population estimates file:
# Assuming the population estimates file is named "population_estimates.csv" and is located in the same directory as this script path = os.path.join(os.getcwd(), "population_estimates.csv")- Load the population estimates file into a dataframe:
df = pd.read_csv(path)- Use the
uslibrary to crosswalk FIPS codes to state abbreviations:
from us import states df['state'] = df['fips_code'].apply(lambda x: states.lookup(x).abbr)- Keep only the state abbreviations in the dataframe:
df = df[['state']] - User
Load the population estimates file into a dataframe. Your data only includes fips codes for states. crosswalk fips codes to state abbreviations. Keep only the state abbreviations in your data.
- Assistant
To load the population estimates file into a DataFrame and crosswalk FIPS codes to state abbreviations, follow the steps below:
- Import the necessary libraries:
import pandas as pd from us import states- Load the population estimates file into a DataFrame:
# Assuming the population estimates file is named "population_estimates.csv" and is in the same directory as this script df = pd.read_csv("population_estimates.csv")- Crosswalk FIPS codes to state abbreviations:
df['state_abbreviation'] = df['fips_code'].map(states.mapping('fips', 'abbr'))- Keep only the state abbreviations in the DataFrame:
df = df[['state_abbreviation']]Putting it all together:
import pandas as pd from us import states df = pd.read_csv("population_estimates.csv") df['state_abbreviation'] = df['fips_code'].map(states.mapping('fips', 'abbr')) df = df[['state_abbreviation']] - User
fips_to_state = { “1”: ‘AL’, “2”: “AK”, “4”: ‘AR’,‘5’: “AR”, “6”: “CA”, “8”: “CO”, “9”: “CT”, “10”: “DE”, “11”: “DC”, “12”: “FL”, “13”: “GA”, “15”: “HI”, “16”: “ID”, “17”: “IL”, “18”: “IN”, “19”: “IA”, “20”: “KS”, “21”: “KY”, “22”: “LA”, “23”: “ME”, “24”: “MD”, “25”: “MA”, “26”: “MI”, “27”: “MN”, “28”: “MS”, “29”: “MO”, “30”: “MT”, “31”: “NE”, “32”: “NV”, “33”: “NH”, “34”: “NJ”, “35”: “NM”, “36”: “NY”, “37”: “NC”, “38”: “ND”, “39”: “OH”, “40”: “OK”, “41”: “OR”, “42”: “PA”, “44”: “RI”, “45”: “SC”, “46”: “SD”, “47”: “TN”, “48”: “TX”, “49”: “UT”, “50”: “VT”, “51”: “VA”, “53”: “WA”, “54”: “WV”, “55”: “WI”, “56”: “WY”, “72”: “PR”}Load the population estimates file into a dataframe. Your data only includes fips codes for states. crosswalk fips codes to state abbreviations. Keep only the state abbreviations in your data.
- Assistant
To load the population estimates file into a DataFrame, crosswalk FIPS codes to state abbreviations using the provided dictionary, and keep only the state abbreviations in the data, you can follow these steps: