Skip to content

labs for session02 through session06 and lightening talk files #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions students/JohnRudolph/session4/sherlock_small.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
One night--it was on the twentieth of March, 1888--I was
returning from a journey to a patient (for I had now returned to
civil practice), when my way led me through Baker Street. As I
passed the well-remembered door, which must always be associated
in my mind with my wooing, and with the dark incidents of the
Study in Scarlet, I was seized with a keen desire to see Holmes
again, and to know how he was employing his extraordinary powers.
His rooms were brilliantly lit, and, even as I looked up, I saw
his tall, spare figure pass twice in a dark silhouette against
the blind. He was pacing the room swiftly, eagerly, with his head
sunk upon his chest and his hands clasped behind him. To me, who
knew his every mood and habit, his attitude and manner told their
own story. He was at work again. He had risen out of his
drug-created dreams and was hot upon the scent of some new
problem. I rang the bell and was shown up to the chamber which
had formerly been in part my own.
69 changes: 69 additions & 0 deletions students/susanRees/LighteningTalkFiles/lighteningTalk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
####################
## import modules ##
####################

# the program opens the workbook by importing the openpyxl module and calling
# the openpyxl.load_workbook() function.
import openpyxl as op
wb = openpyxl.load_workbook('surveyData.xlsx')

def get_age_groups(my_sheet, my_column):
# calls the get_sheet_by_name function to get the worksheet object
sheet = wb.get_sheet_by_name(my_sheet)
# Use the cell() sheet method with row and column keyword arguments
# to pull values from all cells in one column. puts them into a tuple.
rawAgeData = sheet.columns[my_column]
for cellObj in sheet.columns[my_column]:
print(cellObj.value)
# puts them in order
ageDataOrdered = [sorted(rawAgeData)]
# Using a for loop? counts the total number of entries, creates dictionary
# with unique entries (age) as keys, and the number of times each entry
# appears as value?
ageGroups = {}
for items in ageDataOrdered:
if items == items:
ageGroups = {counts(items)}
# remove duplicate items?? use itertools
else:
ageGroups = {counts(items)}
# in new dictionary? iterates through dict values and divides by total
# number of entries to provide the percentage (new value) of the whole that
# each unique entry group (keys) represents
# sorts entries (keys) by percentage (value) to see the order of importance
for keys, values in (ageGroups.items()):
numAges = len(keys)
percentAge = int(values/numAges)
finalNums = {percentAge}
sorted(finalNums, percentAge)

# starts program
if __name__ == '__main__':
my_script.main()

my_sheet = 'path to excel sheet'

# Displays them in a pie (lol) chart or bar graph of some sort?
# example from automate the borimg stuff below.
# import openpyxl
# wb = openpyxl.Workbook()
# sheet = wb.get_active_sheet()
# for i in range(1, 11): # create some data in column A
# sheet['A' + str(i)] = i

# refObj = openpyxl.charts.Reference(sheet, (1, 1), (10, 1))

# seriesObj = openpyxl.charts.Series(refObj, title='First series')

# chartObj = openpyxl.charts.PieChart() # can also use BarChart
# chartObj.append(seriesObj)
# chartObj.drawing.top = 50 # set the position
# chartObj.drawing.left = 100
# chartObj.drawing.width = 300 # set the size
# chartObj.drawing.height = 200

# sheet.add_chart(chartObj)
# wb.save('sampleChart.xlsx')

# convert this program to require user input (which column do you want?) or to
# run on all columns automatically?
42 changes: 42 additions & 0 deletions students/susanRees/LighteningTalkFiles/lighteningTalkPandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Imports pandas
# reads the spreadsheet
# pops the "Age" column out
# uses .value_counts to group ages together and
# sorts them in ascending order according to frequency of occurance

import pandas as pd
df = pd.read_excel("surveyData.xlsx")
ages = df.pop("Age")
print(ages.value_counts(normalize=True, sort=True, ascending=False, bins=None, dropna=True))


# pandas.series.value_counts
# series.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True)

# Returns object containing counts of unique values.

# The resulting object will be in descending order so that the first
# element is the most frequently-occurring element. Excludes NA values
# by default.

# Parameters:

# normalize : boolean, default False
# If True then the object returned will contain the relative
# frequencies of the unique values.

# sort : boolean, default True
# Sort by values

# ascending : boolean, default False
# Sort in ascending order

# bins : integer, optional
# Rather than count values, group them into half-open bins, a
# convenience for pd.cut, only works with numeric data

# dropna : boolean, default True
# Don’t include counts of NaN.

# Returns:
# counts : Series
Binary file not shown.
Binary file not shown.
35 changes: 25 additions & 10 deletions students/susanRees/session02/PrintGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,38 @@ def print_column():
print_column()
print_row()


print_grid(10)


def second_grid(x, y):
n = (y-1)
for n in range(0, n):
def print_rows():
n = (x + 1)
m = (n - 1)
for m in range(0, m):
def print_row():
print('+', end=' '),
print('-' * y, end=' '),
print_rows()
print('+')
def print_columns():
def print_rows():
n = (x + 1)
m = (n - 1)
for m in range (0, m):
print_row()
def print_column():
print('|', end=' '),
print(' ' * y, end=' '),
print_columns()
print('|')
def print_columns():
n = (x + 1)
m = (n - 1)
for m in range (0, m):
print_column()
print_rows()
print('+')
def print_mult_columns():
n = (y + 1)
m = (n - 1)
for m in range (0, m):
print_columns()
print('|')
print_mult_columns()
print_rows()
print('+')
second_grid(3, 4)
second_grid(4, 10)
14 changes: 7 additions & 7 deletions students/susanRees/session03/Lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@


# Make a copy of the original list
backwards_fruits = fruits[0:-1]
backwards_fruits = fruits[:]

# reverse the letters in each fruit in the copy.
# for bwards in backwards_fruits:

# print(backwards_fruits)
for item in backwards_fruits[:]:
bward_item = item[::-1]
backwards_fruits.append(bward_item)

# Delete the last item of the original list.
# fruits.pop(-1)
fruits.pop(-1)

# Display the original list and the copy.
# print(fruits)
# print(backwards_fruits)
print(fruits)
print(backwards_fruits)
53 changes: 37 additions & 16 deletions students/susanRees/session04/DictionaryLab.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,72 @@
# Create a dictionary containing “name”, “city”, and “cake”
# for “Chris” from “Seattle” who likes “Chocolate”.
dict = {'name': "Chris", 'city': "Seattle", 'cake': "Chocolate"}
stuff = {'name': "Chris", 'city': "Seattle", 'cake': "Chocolate"}

# Display the dictionary.
print(dict)
print(stuff)

# Delete the entry for “cake”.
dict.pop('cake')
stuff.pop('cake')

# Display the dictionary.
print(dict)
print(stuff)

# Add an entry for “fruit” with “Mango” and display the dictionary.
dict.update({'fruit': "Mango"})
stuff.update({'fruit': "Mango"})

print(dict)
print(stuff)

# Display the dictionary keys.
print(dict.keys())
print(stuff.keys())


# Display the dictionary values.
print(dict.values())
print(stuff.values())

# Display whether or not “cake” is a key in the dictionary (i.e. False) (now).
print("True" if 'cake' in dict else "False")
print("True" if 'cake' in stuff else "False")

# Display whether or not “Mango” is a value in the dictionary (i.e. True).
print("True" if "Mango" in dict.values() else "False")
print("True" if "Mango" in stuff.values() else "False")

# Using the dictionary from item 1:
# Make a dictionary using same keys but with the number of ‘t’s in each value.
# Not sure I understand the assingment...
stuff = {'name': "Chris".count("t"), 'city': "Seattle".count("t"), 'cake': "Chocolate".count("t")}
print(stuff)

# Create sets s2, s3 and s4 containing numbers from 0-20, divisible 2, 3 and 4.
s2 = set([1:20])
s3 = set([1:20])
s4 = set([1:20])
s2 = set([x for x in range(0, 20) if x % 2 == 0])
s3 = set([x for x in range(0, 20) if x % 3 == 0])
s4 = set([x for x in range(0, 20) if x % 4 == 0])

# Display the sets.
print(s2)
print(s3)
print(s4)

# Display if s3 is a subset of s2 (False)
if s3.issubset(s2):
print(True)
else:
print(False)

# and if s4 is a subset of s2 (True).
if s4.issubset(s2):
print(True)
else:
print(False)

# Create a set with the letters in ‘Python’ and add ‘i’ to the set.
# Create a set with the letters in ‘Python’
python = set(["p", "y", "t", "h", "o", "n"])

#add ‘i’ to the set.
python.update(["i"])
print(python)

# Create a frozenset with the letters in ‘marathon’
marathon = frozenset(["m", "a", "r", "a", "t", "h", "o", "n"])
print(marathon)

# display the union and intersection of the two sets.
# display the union and intersection of the two sets.
print(marathon.union(python))
print(marathon.intersection(python))
36 changes: 36 additions & 0 deletions students/susanRees/session05/comprehensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
feast = ['lambs', 'sloths', 'orangutans', 'breakfast cereals', 'fruit bats']
comprehension = [delicacy.capitalize() for delicacy in feast]
print(comprehension[0])
print(comprehension[2])

comp = [delicacy for delicacy in feast if len(delicacy) > 6]
print(len(feast))
print(len(comp))

list_of_tuples = [(1, 'lumberjack'), (2, 'inquisition'), (4, 'spam')]
comprehension = [skit * number for number, skit in list_of_tuples]
print(comprehension[0])
print(len(comprehension[2]))

eggs = ['poached egg', 'fried egg']
meats = ['lite spam', 'ham spam', 'fried spam']
comprehension = ['{0} and {1}'.format(egg, meat) for egg in eggs for meat in meats]
print(len(comprehension))
print(comprehension[0])

comprehension = {x for x in 'aabbbcccc'}
print(comprehension)

dict_of_weapons = {'first': 'fear', 'second': 'surprise', 'third':'ruthless efficiency', 'forth':'fanatical devotion', 'fifth': None}
dict_comprehension = {k.upper(): weapon for k, weapon in dict_of_weapons.iteritems() if weapon}
print('first' in dict_comprehension)
print('FIRST' in dict_comprehension)
print(len(dict_of_weapons))
print(len(dict_comprehension))

#count_evens([2, 1, 2, 3, 4]) == 3
#count_evens([2, 2, 0]) == 3
#count_evens([1, 3, 5]) == 0

#def count_evens(nums):
# one_line_comprehension_here
12 changes: 12 additions & 0 deletions students/susanRees/session05/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Create a wrapper function, safe_input()
# returns None rather rather than raising the exceptions EOFError or KeyboardInterrupt
# when user enters ^C for Keyboard Interrupt, or ^D (^Z on Windows) for End Of File.

def safe_input():
try:
input("Type something here")
except (EOFError, KeyboardInterrupt):
return None
else:
print("Thanks.")
safe_input()
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.