Data Review and Wrap-Up
In this session we will do some more advanced file manipulation and discuss strategies for using ChatGPT to develop self-learning projects and help with programming information science type programs.
We will work on an in-class project to cover sorting, popping, lambdas. You can look at the below Videos for help with these topics.
- Good Overview of Lambda Functions in Python (lamdas are helpful for sorting dictionaries or other complex structures)
- Good Overview of Pop Method
- Good Sorting Video (We have not covered objects, so don't get blown away with the sorting objects demo; you can stop watching after sorting dictionaries)
Pandas is needed for your UNC Basketball roster Assignment.
Learning to work with files via ChatGPT prompts
ChatGPT is an excellent tutor for learning Python or beginning Computer Science concepts.
Never input sensitive data into ChatGPT!
As a freelancer, I need to protect my own code and my client's data. As a contract instructor for UNC, I would never input a list of student data to explore text transformations in ChatGPT.
Two ways you can get help from ChatGPT in these situations:
- Abstract the problem: describe the problem or create a hypothetical example.
- Use Dummy Data: you can even ask ChatGPT to create the dummy data in the format you want.
I decided to ask ChatGPT for a list of 30 notable individuals from the 20th century which we could use in class for file transformation demos.
Notable 20th Century Individuals
So I asked: can (sic) you create a markdown list of 30 notable 20th century individuals with a link to there (sic) wikipedia (sic) page?
I normally fire off prompts very quickly and don't worry about spelling, or capitalization.
This is what I envisioned that I would get:
| **Name** | **Wikipedia Link** |
|-------------------|---------------------------------------------------------|
| Albert Einstein | [Link](https://en.wikipedia.org/wiki/Albert_Einstein) |
| Mahatma Gandhi | [Link](https://en.wikipedia.org/wiki/Mahatma_Gandhi) |
| Winston Churchill | [Link](https://en.wikipedia.org/wiki/Winston_Churchill) |
and the rest...
This is what I got:
Here is a list of 30 notable 20th-century individuals along with links to their Wikipedia pages:
- Albert Einstein
- Mahatma Gandhi
- Winston Churchill
- And the rest ....
So here was the problem: I envisioned a Markdown Table, but I asked for a list. It gave me an ordered list in Markdown, but as a result, not the ordered list code view:
1. [Albert Einstein](https://en.wikipedia.org/wiki/Albert_Einstein)
2. [Mahatma Gandhi](https://en.wikipedia.org/wiki/Albert_Einstein)
3. [Winston Churchill](https://en.wikipedia.org/wiki/Albert_Einstein)
4. And the rest ....
Therefore, even when working with Markdown, which is a very simplifed abstraction of HTML, you may need to be careful to be very specific in your prompts.
To see the progression of prompts, you can view this saved page to all of the prompts to generate this file: Notable 20th Century Individuals.
After I started working with the file, I decided I wanted to have an extra column separating the first
and last
name and move the last
name column to before the first name column.
I went back to ChatGPT and it was able to do that for me. I asked it to sort the table by last name. It seemed to choke on the single X for the Malcom X row. I then asked it to remove the "No." column. It could then sort by last name. I then asked it to add back the "No." Column and add the 1 - 30 numbers. That seemed to work. Below is the refactored Markdown table from ChatGPT.
| **No.** | **Last** | **First** | **Wikipedia Link** | **Notability** |
|---------|-------------------|----------------|-------------------------------------------------------|--------------------------------------------|
| 1 | Ali | Muhammad | [Link](https://en.wikipedia.org/wiki/Muhammad_Ali) | Boxing legend, civil rights advocate |
| 2 | Armstrong | Neil | [Link](https://en.wikipedia.org/wiki/Neil_Armstrong) | First human on the Moon |
| 3 | Castro | Fidel | [Link](https://en.wikipedia.org/wiki/Fidel_Castro) | Cuban revolutionary and President |
| 4 | Chaplin | Charlie | [Link](https://en.wikipedia.org/wiki/Charlie_Chaplin) | Silent film actor, comedian, filmmaker |
| 5 | Churchill | Winston | [Link](https://en.wikipedia.org/wiki/Winston_Churchill) | Prime Minister of the UK during WWII |
| 6 | Curie | Marie | [Link](https://en.wikipedia.org/wiki/Marie_Curie) | Pioneer in radioactivity research |
| 7 | Einstein | Albert | [Link](https://en.wikipedia.org/wiki/Albert_Einstein) | Theoretical physicist, Theory of Relativity |
| 8 | Freud | Sigmund | [Link](https://en.wikipedia.org/wiki/Sigmund_Freud) | Founder of psychoanalysis |
| 9 | Gandhi | Mahatma | [Link](https://en.wikipedia.org/wiki/Mahatma_Gandhi) | Leader of Indian independence movement |
| 10 | Gorbachev | Mikhail | [Link](https://en.wikipedia.org/wiki/Mikhail_Gorbachev) | Last leader of the Soviet Union, reforms |
| 11 | Guevara | Che | [Link](https://en.wikipedia.org/wiki/Che_Guevara) | Marxist revolutionary, key in Cuban Revolution |
| 12 | Hawking | Stephen | [Link](https://en.wikipedia.org/wiki/Stephen_Hawking) | Theoretical physicist, black hole research |
| 13 | Hemingway | Ernest | [Link](https://en.wikipedia.org/wiki/Ernest_Hemingway) | Novelist, known for *The Old Man and the Sea* |
| 14 | Hepburn | Audrey | [Link](https://en.wikipedia.org/wiki/Audrey_Hepburn) | Actress and humanitarian |
| 15 | Holiday | Billie | [Link](https://en.wikipedia.org/wiki/Billie_Holiday) | Influential jazz and blues singer |
| 16 | Jobs | Steve | [Link](https://en.wikipedia.org/wiki/Steve_Jobs) | Co-founder of Apple, tech visionary |
| 17 | Joyce | James | [Link](https://en.wikipedia.org/wiki/James_Joyce) | Influential modernist writer, *Ulysses* |
| 18 | Kahlo | Frida | [Link](https://en.wikipedia.org/wiki/Frida_Kahlo) | Iconic Mexican painter, self-portraits |
| 19 | Kennedy | John F. | [Link](https://en.wikipedia.org/wiki/John_F._Kennedy) | US President, Cuban Missile Crisis |
| 20 | Kennedy Onassis | Jacqueline | [Link](https://en.wikipedia.org/wiki/Jacqueline_Kennedy_Onassis) | First Lady of the United States, style icon |
| 21 | King Jr. | Martin Luther | [Link](https://en.wikipedia.org/wiki/Martin_Luther_King_Jr.) | Civil rights leader, "I Have a Dream" speech |
| 22 | Lamarr | Hedy | [Link](https://en.wikipedia.org/wiki/Hedy_Lamarr) | Actress and inventor, wireless tech pioneer |
| 23 | Mandela | Nelson | [Link](https://en.wikipedia.org/wiki/Nelson_Mandela) | Anti-apartheid revolutionary, South African President |
| 24 | Picasso | Pablo | [Link](https://en.wikipedia.org/wiki/Pablo_Picasso) | Influential 20th-century artist, Cubism |
| 25 | Roosevelt | Franklin D. | [Link](https://en.wikipedia.org/wiki/Franklin_D._Roosevelt) | US President during the Great Depression and WWII |
| 26 | Teresa | Mother | [Link](https://en.wikipedia.org/wiki/Mother_Teresa) | Humanitarian, Nobel Peace Prize laureate |
| 27 | Thatcher | Margaret | [Link](https://en.wikipedia.org/wiki/Margaret_Thatcher) | First female UK Prime Minister |
| 28 | Tolkien | J.R.R. | [Link](https://en.wikipedia.org/wiki/J._R._R._Tolkien) | Author of *The Lord of the Rings* |
| 29 | Warhol | Andy | [Link](https://en.wikipedia.org/wiki/Andy_Warhol) | Leading figure in the Pop Art movement |
| 30 | X | Malcolm | [Link](https://en.wikipedia.org/wiki/Malcolm_X) | Civil rights activist, Black empowerment |