Lecture 8: Kiva
Overview
The lecture introduces Linux and course logistics, then teaches Python loops and list operations through a Kiva microloan dataset. Students calculate totals, averages, minimums and maximums, identify the countries associated with extreme loans, and count loans by country using functions such as len, max, min, sum, index, and count.
Key takeaways
- Python’s len, max, min, and sum functions provide direct ways to measure a list, while a for loop with += demonstrates how to calculate a total manually.
- Python lists use zero-based indexing, so a 25-element list has valid indices from 0 through 24; negative index -1 retrieves the final element.
- Parallel Kiva lists preserve row relationships by position, allowing loan_amount.index(max_loan) to locate the matching country_name entry.
- The Kiva exercise uses about 1.4 million records in its full dataset but presents 25 sample loans for introductory statistics and programming practice.
- The mean is computed as a total divided by the number of observations, and unlike the median it can be strongly affected by extreme values.
- The list and string count() method supports country-frequency analysis, including printing each unique country with its number of loans.
Chapters
- Linux is a family of operating systems built around the Linux kernel, which mediates between hardware and software.
- Windows targets diverse hardware, while Apple can optimize macOS for specific hardware configurations it controls.
- macOS is Unix-based, and virtual machines make it easy to try another operating system without replacing the current one.
- Linux is useful for computing students because Professor Rosen estimates that roughly 90% of web servers run some form of Linux.
- The practice exam is intended to be harder than the real exam and includes extra zero-point questions for timing practice.
- The first exam is expected around week six, the second around week eleven, and the third during the final lecture.
- Students must take the exam during their assigned lab; the course drops the lowest of three exam scores.
- The final exam can serve as a makeup opportunity, reducing the impact of a missed exam or a poor earlier result.
- The assignment combines text-based exercises, including the 99 Bottles of Beer song, a multiplication table, and a sum-of-squares function.
- The turtle exercises build reusable functions: draw a square, a row of squares, a grid, and stairs.
- The super spiral draws 36 hexagons, turning slightly between shapes to create the spiral pattern.
- Optional work includes formatting loop output and adding color transitions such as blue to purple.
- Kiva lets donors direct a contribution, with a stated minimum of $25, to a selected microloan project.
- When a borrower repays a loan, the funds return to the donor’s Kiva account and can be lent to another project.
- Small loans can have different purchasing power across countries, particularly for food, clothing, supplies, and business materials.
- Kiva has operated since 2005 and provides loan records for practicing introductory data analysis.
- The full dataset contains about 1.4 million rows, while the Runestone exercise displays a sample of 25 loans.
- Each row represents one loan, with columns for loan amount, country name, time to raise, and total number of lenders.
- The exercise excludes loan IDs because they identify records internally, and status because every displayed loan is funded.
- A $250 loan could be funded by ten lenders contributing $25 each, while a $150 loan could have one lender.
- Runestone preloads each dataset column as a Python list, so names such as loan_amount can be used without defining them in the exercise.
- Lists are changeable and can grow; fixed-size arrays have different constraints, though Python lists can use array-list machinery internally.
- Corresponding positions across loan_amount, country_name, and num_lenders_total refer to fields from the same loan record.
- The lecture distinguishes Python lists from arrays while noting that the terms and behavior vary across programming languages.
- Python list indices start at 0, so loan_amount[0] retrieves the first loan and loan_amount[1] retrieves the second.
- len(loan_amount) returns 25 for the sample, making valid indices 0 through 24 rather than 1 through 25.
- Requesting index 25 produces a list-index-out-of-range error because the final valid position is 24.
- Square brackets perform list subscripting, while parentheses are used for function calls such as len(loan_amount).
- Python supports negative indices: loan_amount[-1] retrieves the final loan amount without calculating len(loan_amount) - 1.
- The built-ins max, min, and sum return the largest value, smallest value, and total for a numeric list.
- The lecture connects list subscripts to mathematical vector notation, explaining why brackets are used in code.
- For strings, max and min use alphabetical ordering; for the word temple, the maximum character is t and the minimum is e.
- The exercise asks students to store the total loan amount in a variable named loan_total.
- Because the task requires manual accumulation rather than sum(), loan_total starts at 0 and a for loop visits each value in loan_amount.
- The loop uses loan_total += amount to add each loan to the running total.
- The 25 displayed loans sum to 1,657, which the Runestone unit test checks.
- The mean is calculated by dividing the sum of all loan amounts by the number of loans, which can be obtained with len().
- The mean can be influenced by unusually large or small values, while the median identifies the middle value in an ordered set.
- max(loan_amount) returns 1,800 and min(loan_amount) returns the smallest loan in the sample.
- The corresponding country names require matching the loan’s position to the country_name list.
- Values at the same index in loan_amount and country_name belong to the same loan record.
- loan_amount.index(max_loan) finds the position of the largest loan, and country_name at that position identifies its country.
- The $1,800 maximum loan is associated with Georgia in the sample.
- The index() method returns the first occurrence when a value appears more than once; the same approach finds the minimum-loan country.
- The average number of lenders per loan uses the same accumulation pattern as loan_total, but iterates through num_lenders_total and divides by the number of loans.
- country_name.count("Philippines") counts matching country entries; capitalization must match the stored data.
- The final exercise loops through unique_countries and prints each country alongside country_name.count(name).
- The country-frequency output counts loans per country, not the number of lenders; the result is checked with Runestone unit tests.
Transcript excerpt
0:00 So, over the next few weeks, I'm going to be um documenting my troubles and transitions as I as I try transitioning a few of my devices over to Linux. Right here, I'm using a machine that already is running Linux, which is a Steam Deck, just a tiny handheld computer. Um for the So, this is a good time as any. Um basically, there are three primary operating systems these days. There's Windows PCs, there's uh Mac OSx based computers, and then there are computers running Linux. Uh most consumer products do not come with Linux. Most uh software manufacturers, most hardware manufacturers aside from Windows, sorry, aside from um Apple
0:50 basically are shipping with Windows as the primary operating system. Dell being an exception that you can get uh some systems on Linux. There's a few other sellers who will uh sell Linux. Um but typically the most time you'll experience Linux if you're running something that like has the Steam OS on it which is built on Linux. Windows is an interesting system. I um it is compatible with like almost anything. and that's kind of a both a blessing and a curse for it. Um, Apple computers are really nifty, but they lack a level of customization that I like. But on the other hand, what's really amazing about Apple computers is because Apple controls both the hardware and software, they have a level of uh
1:42 flex, not flexibility, but of configuration that they can do internally that Windows can only dream of because Windows has to assume these are uh that I'm going to be in throwing this on any laptop, including a laptop that's barely able to run it. Whereas Apple devices are like, "No, we know that this model with this processor will
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Professor Rosen.