Code Portfolio Example#
READ THIS: You are expected to create at least one item per class period (roughly days 1-10 for the checkpoint and days 1-24 for the final assignment). How the items are structured is up to you (markdown, code, images, etc.), but they need to be noted by the class day (see the example below for reference). If you have any questions, please reach out to your section instructor!
Day 3#
Looping by Index#
The code below loops by index over the value of x and adds 4 to all of the values.
When I use this code, I need to change:
range(len(x))(specifically, the valuex) to whatever we are looping over.x[gg] = x[gg]+4To whatever procedure we want the loop to be repeating.
x = [4,12,16,22,33,49]
for gg in range(len(x)):
x[gg] = x[gg]+4
Reading in Data Using Pandas#
1-24-22#
The code below reads in a .csv file using Pandas’s read_csv function. This should really only be used for CSV files or Excel files (using read_excel). Use Numpy’s fromfile to read in binary (.bin) or Yaff (.yaff) files.
When I use this code, I need to change:
datato be a more descriptive variable name.dataset.csvto the name of the data file.delimeterif the delimeter isn’t a comma (other delimeters include;).skiprowsif there are rows at the top of the file I want to skip.encodingif the encoding is something other thanutf-8(other encodings includeutf-16be).
import pandas as pd
data = pd.read_csv("dataset.csv",delimiter=',',skiprows=0,encoding='utf-8')
Reading in Data Using Numpy#
1-24-22#
The code below reads in a .bin file using Numpy’s fromfile function. This works for all kinds of file types, including binary (.bin) and yaff (.yaff).
When I use this code, I need to change:
datato be a more descriptive variable name.dataset.binto the name of the data file.dtypeto be whatever the data type that this file uses (other commonly used types arefloat32).
import numpy as np
data = np.fromfile('dataset.bin', dtype='int32')
Making a Plot#
1-24-22#
The code below creates a plot showing x_data versus y_data.
When I use this code, I need to change:
x_datato whatever myxvariable is.y_datato whatever myyvariable is.labelto whatever the label fo this dataset is.xlabelto whatever the name of myxvariable is.ylabelto whatever the name of myyvariable is.titleto whatever the title of this figure should be.
import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(x_data,y_data,label="X Data")
plt.xlabel("X Data")
plt.ylabel("Y Data")
plt.title("X Vs. Y Dataset")
plt.grid()