My Second Python Program
For my second effort, I had AI do the coding. What I asked for was this:
Write Python code to import history.csv into a frame. Name columns "title" and "date". Copy the title column to a list called raw_titles. Make a new list strip_titles from raw_titles, where the text contains only raw_title text up to the first ":" Save unique elements of strip_titles in alphabetical order as a new file csv called unique_titles.
That request reflects some vague idea of what's possible and what I want, but it's English, not Python. Perplexity gave me this:
import pandas as pd
# Load the CSV file into a DataFrame and specify the column names
df = pd.read_csv('history.csv', names=['title', 'date'], header=0)
# Copy the 'title' column to a list called raw_titles
raw_titles = df['title'].tolist()
# Create a new list strip_titles from raw_titles, where the text contains only raw_title text up to the first ":"
strip_titles = [title.split(':')[0] for title in raw_titles]
# Get unique elements from strip_titles and sort them alphabetically
unique_strip_titles = sorted(list(set(strip_titles)))
# Save unique elements of strip_titles as a CSV file called unique_titles.csv
unique_titles_df = pd.DataFrame(unique_strip_titles, columns=['title'])
unique_titles_df.to_csv('unique_titles.csv', index=False)
Note that Perplexity helpfully provides comments, which educate me about how Python solves the problem. In fact, AI can give me a very detailed explanation of how all this works.
But why do this?
You can get a list of movies you have seen on Netflix (left as homework for the reader) but it has entries for each episode of long-running series like "Broken Bad." That's why I need to get rid of the ":" and ask for unique titles.
But why do this?
The resulting file (unique_titles.csv) can be directly dragged into a Perplexity prompt to become the "context" for a discussion. See the result here. Coding 7 lines of Python to get this result did involve a bit of a learning curve, but no actual coding was required. This is truly my 2nd Python program, and I really didn't write it. I'm still personally back at "Hello World." The key insight was actually the need to hand Perplexity as small a file as possible. There is a limit to how much "context" an AI can "remember". Today. There is a trend to increase this limit from a few hundred characters to megabytes.
For your information, this is what "unique_titles" looks like:
13 Going on 30
1899
2012
3
3%
365 Days
A Beautiful Life
A Man of Action
A Perfect Murder
A Quiet Place Part II
A Trip to Infinity
After Life
After We Fell
Age of Tanks
Agent Elvis
Alexander
Alias Grace
All Quiet on the Western Front
All the Light We Cannot See
All the Money in the World
Always Shine
American Gangster
American Girl
American Woman
Anatomy of a Scandal
Ancient Apocalypse
And so on ...
Netflix provided me with a file that looks like this:
"Griselda: Limited Series: Adios, Miami",2024-02-18
Griselda: Limited Series: Paradise Lost,2024-02-17
Griselda: Limited Series: Middle Management,2024-02-16
Griselda: Limited Series: Mutiny,2024-02-16
Griselda: Limited Series: Lady Comes to Town,2024-02-16
Raël: The Alien Prophet: Limited Series: Raël Superstar,2024-02-16
Raël: The Alien Prophet: Limited Series: Genesis,2024-02-16
Working: What We Do All Day: Limited Series: The Middle,2024-02-16
ROMA,2024-02-16
Griselda: Limited Series: Rich White People,2024-02-15
American Girl,2024-02-14
No Limit,2024-02-14
365 Days,2024-02-14
Once Upon a Time in Hollywood,2024-02-14
Always Shine,2024-02-13
The Deepest Breath,2024-02-13
Inside the Mind of a Cat,2024-02-12
Talk to Me,2024-02-12
Lead Me Home,2024-02-12
War Dogs,2024-02-11
Outer Banks: Season 1: Pilot,2024-02-09
Safe: Season 1: Episode 8,2024-02-09
Safe: Season 1: Episode 7,2024-02-09
Safe: Season 1: Episode 6,2024-02-08
Safe: Season 1: Episode 5,2024-02-08
Safe: Season 1: Episode 4,2024-02-08
Safe: Season 1: Episode 3,2024-02-07
Safe: Season 1: Episode 2,2024-02-07
Safe: Season 1: Episode 1,2024-02-07
===============
This is not foolproof. Perplexity can't find titles that are obviously in the file for totally opaque reasons but then changes its "mind", apologizes and makes up stupid excuses. It's very evident that AI's logic is not necessarily what a human would follow. There is no way to know that until things go sideways. It's quite possible that errors will go undetected. Also, slight variations in the approach, such as reading from an Excel file rather than CSV, land you in "import Hell," where the required module is/is not installed. This had me stuck or many days before I even attempted the seemingly magical solution here. Getting your modules right is the next step after "Hello World".
The last time I was paid to do anything with computers, my group was called "the plumbers." Our job was to tie big applications together so they would "talk" to each other. For example, an application that accessed the library would need to talk to the application that logged people in and the application that said whether access was permitted. There was little or no "programming" involved. Talking to AI is a bit like that. It was the most boring job I had in over 50 years. It was a relief when the crash of 2008 caused half of the department to be laid off.
All this can be funny until you realize that AI is being trusted in some applications with life-and-death situations. For example, Tesla cars running on "fully automatic" happily stop for children and then run them over.
You can also see this in the ordinary jobs I give AI every day. More on that later ...

Comments
Post a Comment