Question

In: Computer Science

in the pandas_names notebook, write python code to analyze and plot how popular your name is...

in the pandas_names notebook, write python code to analyze and plot how popular your name is compared to one of your family member..

alberto and arturo

if your name is not in the dataset use "penny"as a female name and "ken" as male name.

Solutions

Expert Solution

#code in text

#!/usr/bin/env python
# coding: utf-8

# In[2]:


import numpy as np
import pandas as pd
import seaborn
import matplotlib.pyplot as plt
import os


# In[4]:


cd names/


# In[7]:


os.listdir("C:/Users/Gopal/Desktop/names")
#Each .txt file contains Name, Sex, and the number of babies born that year(1880 to 2018) with that name


# In[10]:


# read any of them
open(os.listdir("C:/Users/Gopal/Desktop/names")[0],'r').readlines()[:8]


# In[38]:


# collect each year of data
All_year_data=[]
# loop over all file in listdir
Year=1880
for ix in os.listdir("C:/Users/Gopal/Desktop/names") :
All_year_data.append(pd.read_csv(ix,names=['name','sex','number']))
All_year_data[-1]['year'] = Year
Year=Year+1

final_data=pd.concat(All_year_data)# Concatenate every year data
final_data.head(n=100)


# In[39]:


#Generate indexed data.
final_data = final_data.set_index(['sex','name','year']).sort_index(level=0)


# In[40]:


final_data.head()


# In[44]:


def popularname(sex,name):
new_data=final_data.loc[sex,name]
#print(new_data)
plt.plot(new_data.index,new_data.values)


# In[51]:


# plot the fig
plt.figure(figsize=(8,8))
plt.title("Popular Name")

# define the dictonary to store name and sex to plot the fig
dic={"Penny":"F",
"Ken":"M"
}

# function call for plot given dictonary

for name,sex in dic.items():
popularname(sex,name)
plt.legend(dic.keys())
plt.xlabel("Y ear")
plt.ylabel("no of time name occure")
plt.show()
plt.savefig("name.png")



Related Solutions

Create a new Python 3 Jupyter Notebook. At the top, be sure to name your notebook...
Create a new Python 3 Jupyter Notebook. At the top, be sure to name your notebook as "*assignment 2.08 - Your Name Here.ipynb*" (obviously, replace the "Your Name Here" part with your actual name). Create a single python cell to program the following specifications. Use what you've learned on this page to: 1. Find the index of "lmno" in the English alphabet using an appropriate instruction and store it in a variable. (hint: you'll need to define a string that...
Please give me an example of how we import stock data in jupyter notebook(Python) and analyze...
Please give me an example of how we import stock data in jupyter notebook(Python) and analyze each step.
Python Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
Write a python code that uses the Euler Implicit method to approximate/plot the solutions to each...
Write a python code that uses the Euler Implicit method to approximate/plot the solutions to each of the following initial-value y′=−ty+4t/y, 0 ≤ t ≤ 1, y(0)=1, with h=0.1 y′=y2+yt, 1 ≤ t ≤ 3, y(l)=−2, with h=0.2
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
please use Jupter notebook in python 3 to answer the following: Plot the hyperbolic paraboloid given...
please use Jupter notebook in python 3 to answer the following: Plot the hyperbolic paraboloid given by: z = x**2/a**2 - y**2/b**2. You may use any non-negative integer values for a and b.
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Programming Python Jupiter notebook Write a Python program that gets a numeric grade (on a scale...
Programming Python Jupiter notebook Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range, it asks him/her to enter a numeric input in the correct range, instead of returning an error. Example: Enter your score: 78 Letter...
create a new Python 3 Jupyter Notebook.. Create one python code cell for the problem below....
create a new Python 3 Jupyter Notebook.. Create one python code cell for the problem below. Use any additional variables and comments as needed to program a solution to the corresponding problem. All functions should be defined at the top of the code in alphabetical order. Problem: Define a function with the following characteristics: The function's purpose will be checking that a number matches another, so it should be named appropriately. It must accept one parameter, which is the number...
Create a new Python 3 Jupyter Notebook. Create one python code cell for the problem below....
Create a new Python 3 Jupyter Notebook. Create one python code cell for the problem below. Use any additional variables and comments as needed to program a solution to the corresponding problem. All functions should be defined at the top of the code in alphabetical order. When done, download the ipynb file and submit it to the appropriate dropbox in the course's canvas page. Problem: Define a function with the following characteristics: The function's purpose will be calculating a factORRial...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT