Startup Transformation

Here is my code:

import codecademylib3

from sklearn import preprocessing

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import numpy as np

load in financial data

financial_data = pd.read_csv(‘financial_data.csv’)

code goes here

print(financial_data.head())

month = financial_data[‘Month’]

revenue = financial_data[‘Revenue’]

expenses = financial_data[‘Expenses’]

plt.plot(month,revenue)

plt.xlabel(‘Month’)

plt.ylabel(‘Amount ($)’)

plt.title(‘Revenue’)

plt.show()

plt.clf()

plt.plot(month,expenses)

plt.xlabel(‘Month’)

plt.ylabel(‘Amount ($)’)

plt.title(‘Expenses’)

plt.show()

expense_overview = pd.read_csv(‘expenses.csv’)

print(expense_overview.head(10))

expense_categories = expense_overview[‘Expense’]

proportions = expense_overview[‘Proportion’]

plt.clf()

plt.pie(proportions, labels = expense_categories)

plt.title(‘Expense Categories’)

plt.axis(‘Equal’)

plt.tight_layout()

plt.show()

expense_categories = [‘Salaries’, ‘Advertising’, ‘Office Rent’, ‘Other’]

proportions = [0.62, 0.15, 0.15, 0.08]

plt.clf()

plt.pie(proportions, labels = expense_categories)

plt.title(‘Expense Categories’)

plt.axis(‘Equal’)

plt.tight_layout()

plt.show()

expense_cut = max(expense_categories)

print("If the company wants to cut costs in a big way, they should focus on " + expense_cut)

employees = pd.read_csv(‘employees.csv’)

print(employees.head())

sorted_productivity = employees.sort_values(by=[‘Productivity’])

print(sorted_productivity)

employees_cut = sorted_productivity.head(100)

print(employees_cut)

transformation = “Sarah should transform the data by using standardization”

print(transformation)

commute_times = employees[‘Commute Time’]

print(commute_times.describe())

commute_times_log = np.log(commute_times)

plt.clf()

plt.hist(commute_times_log)

plt.title(“Employee Commute Times”)

plt.xlabel(“Commute Time”)

plt.ylabel(“Frequency”)

plt.show()

Did your plots come out ok?
Did you do this in Jupyter Notebook too or just do it in the lesson’s terminal window?

Did you do the EXTRA number 21? I am having a hard time with that.
Regards!

Consider knocking together a question- FAQ: How to ask good questions if there’s a section causing you trouble, including some basics about what you tried and what you expected to happen. You’d have a better chance at a response and it may also help learners in the future.

1 Like

Hi,

I have a question regarding the second instruction :
Store each column in three separate variables called month , revenue , and expenses .

I know we can do it manually by setting up each variable to the desired column, However is there a way to iterate over the columns and assign each column to a variable using some function???

Just wondering if we have a lot of columns and we want to extract each one in a different variable can we do it with iteration??

I’m not sure if you’re still interested in this. Yet, here are my codes.

scaler = StandardScaler()
data = employees[['Salary', 'Productivity']].to_numpy()

standard_data = scaler.fit_transform(data)

x = standard_data[:,0]
y = standard_data[:,1]
plt.scatter(x,y)
plt.show()

2 Likes