This Is How ChatGPT Taught Me 5 Mind-Blowing Python One-Liners for Data Science

ChatGPT simplifies Data Science using Python one-liners for AI, Data Analysis, and Machine Learning tasks.

April 15, 2025
This Is How ChatGPT Taught Me 5 Mind-Blowing Python One-Liners for Data Science

Created with GPT 4o

I was analyzing the datasets and searching for different flavors.

Not just numbers, but meaning.

Then I remembered the longevity dataset. Because I sometimes had to remind myself to develop better habits, I downloaded it to recheck it, but I want to do it faster.

So I opened ChatGPT and used this prompt:

“Show me one-liners that turn this messy life expectancy data into something meaningful.”

I like the output, but as a data scientist, I had to do more, so I split the data science into disciplines like Data Exploration, Data Visualization, and Machine Learning, and revised my prompt.

In this one, let’s discover how I revised prompts to generate one-liners with the help of ChatGPT, so let’s see!

Acquaintance

 

Photo by Vladislav Klapin on Unsplash

 

First, send the dataset and dataset description that you’ll work on to ChatGPT.

And tell them that you will generate one-liner Python for upcoming requests.

More info will give you better results.

The Map of the Unknown- Data Exploration

Photo by Annie Spratt on Unsplash

 

I didn’t know what to expect.

So I asked: Which habits are saving our lives — and by how much?” So I typed this as a prompt to ChatGPT.

Sort lifestyle factors by how much they increase or decrease life expectancy and print the top 3 in one line

Here is the code ChatGPT outputs:

df.sort_values('Years gained / lost', ascending=False)[['Factor', 'Years gained / lost']].head(3)

Here is the output.

SS of the output

The Crystal Wall — Data Visualization

 

Photo by Jason D on Unsplash

 

I had the numbers. But I couldn’t feel them—not until I saw them stacked side by side. Let’s use the following prompt;

Show a horizontal bar chart ranking all lifestyle factors by years gained or lost.

Here is the code it generates;

df.sort_values('Years gained / lost').set_index('Factor')['Years gained / lost'].plot(kind='barh', figsize=(8, 10))

 

Here is the output;

SS of the output

With a single line, I transformed the dataset into a visual ladder of life — every bar a habit, every length a decision.

At the top: spending more time with women, healthy eating, and a healthy lifestyle.
At the bottom: alcohol, mental illness, and smoking.

The Wise Oracle — Data Analysis

 

Photo by T A T I A N A on Unsplash

 

Not every claim is created equal. I needed to know: Which habits were backed by actual science — and which were just hype?

Filter for strong scientific evidence and rank lifestyle habits by their life-extending impact.

Here is the code it generates.

df[df['strength of science as a number'] >= 2].sort_values('Years gained / lost', ascending=False)[['Factor', 'Years gained / lost']]

Here is the output.

 

SS of the output

 

The Final Trial — Machine Learning

 

Photo by Sandra Dempsey on Unsplash

 

Could the strength of science alone predict how many years a habit gives or takes?

So let’s use this prompt;

Use linear regression to test if science strength predicts years gained/lost.

Here is the code it generates;

from sklearn.linear_model import LinearRegression; print(LinearRegression().fit(df[['strength of science as a number']], df['Years gained / lost']).coef_)

Here is the output.

 

SS of the output

 

Turns out, it’s often the most well-researched habits (like smoking, alcohol, and poor diet) that steal the most years.

When the Agent Took Over

 

Reference

 

At some point, I realized: why should I write even these one-liners? What if I used a tool that runs them for me?

Then I uploaded the dataset to the LearnAIWithMe Data Explorer, and it automates!

Let’s use the prompt that ChatGPT creates and use the AI Assistant section of LearnAIWithMe Data Explorer. Here is the result;

SS of LearnAIWithMe Data Explorer

 

Amazing, isn’t it?

Final Thoughts

Five years ago, this process lasted 10 times more than now. So everything is changing, but you must ask yourself, did you adapt?

Or even better question, will you?

Thanks for reading this one. Join our community to follow AI news, use our assistants, agents, and more from our platform, here.

Here are the free resources.

Here is the ChatGPT cheat sheet.

Here is the Prompt Techniques cheat sheet.

Here is my NumPy cheat sheet.

Here is the source code of the “How to be a Billionaire” data project.

Here is the source code of the “Classification Task with 6 Different Algorithms using Python” data project.

Here is the source code of the “Decision Tree in Energy Efficiency Analysis” data project.

Here is the source code of the “DataDrivenInvestor 2022 Articles Analysis” data project.

“Machine learning is the last invention that humanity will ever need to make.” Nick Bostrom