liveBook · Manning

ChatGPT

As explained in Starting Data Analytics with Generative AI and Python

A conversational generative-AI system developed by OpenAI that responds to user prompts with generated content.

ChatGPT is a conversational generative-AI system that can help with data analysis. Ask it a question through a web interface, or send prompts from a program through the OpenAI API. Treat its answer as a proposal to inspect, not a result to trust automatically: the useful question is whether it helps you complete and check your particular analysis. section 1.3.1 section 5.7

Choose an access route that fits the task:

  • Use the web interface for a conversational question or, where available, a file upload. Check upload support and keep confidential or personally identifiable data out of the service. section 1.3.1 section 5.3.3
  • Use the OpenAI API to send prompts and receive responses in a Python workflow. It requires an API key; check current documentation, access, and pricing before relying on example code. section 1.3.3 section 6.2.3

Find positive customer reviews

Suppose a dataframe contains Portuguese customer reviews in review_comment_message. Prompt ChatGPT for Python code that extracts positive reviews by keyword. A first response loads the CSV with pandas, checks each review against positive words, marks matching rows, and saves them. That is a starting point, not a finished classifier: ask specifically about missing values and cleaning, run the code, and inspect reviews it includes and excludes. section 5.5.6 section 5.7

Test sentiment rather than guessing its accuracy

ChatGPT can also classify reviews directly instead of supplying keyword-search code. In one API workflow, Python sends each of 500 non-empty reviews with a sentiment prompt, then extracts a label from the response. Review scores serve as a reference for calculating sensitivity and specificity. The ChatGPT 4 API approach reached 0.74 sensitivity and 0.93 specificity for positive reviews, versus 0.45 and 0.90 for the basic keyword search. These are results for that sample, not a guarantee for another dataset; the simple response-label parser can miss nuanced answers. section 6.2.3

Table 6.2 Quality of sentiment analysis with ChatGPT 4 API
Sentiment analysis ( n=500)
Number of reviews classified as positive
Sensitivity
Specificity
Reference review score
320 (64%)
true positives
1
1
Basic keyword search
163 (33%)
0.45
0.9
ChatGPT 4 API
250 (50%)
0.74
0.93

Compare the review-score reference, keyword search, and ChatGPT 4 API results. The table makes clear why counting classified reviews alone is not enough: sensitivity and specificity assess different kinds of errors. section 6.2.3

Other useful prompts ask for possible explanations of a delivery-time pattern, summaries of customer complaints, or code converted between languages. A plausible logistics explanation remains a hypothesis to check against business records. Likewise, a summary can omit nuance, and converted code can introduce bugs. Describe the decision and input clearly, then verify the answer against data or execution results. section 4.5 section 6.3.3 section 7.4

For a large or complicated analysis, divide the work into manageable stages and supervise each output. Check data formatting and context before uploading files; inspect generated formats before parsing them; and test alternative methods on a smaller sample when accuracy or cost matters. ChatGPT may give a basic default solution, make hidden assumptions, or agree with a mistaken objection. Its value lies in a workflow that leaves you able to catch those failures. section 5.3.3 section 5.5.3 section 5.5.6 section 5.7

How Starting Data Analytics with Generative AI and Python covers it

How deep it goes
Works through prompts, Python API calls, output checks, and measured results rather than model architecture.
Examples
Uses Portuguese customer reviews, a 500-review sentiment test, and regional delivery-time differences as analytical cases.
What it assumes
Begins with plain-language web queries but assumes Python and dataframe familiarity for coding workflows; targeted text-mining knowledge helps improve basic answers.
What you can do after
Apply it via the web interface or OpenAI API to propose analytical steps, then validate code and findings against data.
How it connects
Connects ChatGPT to the OpenAI API, pandas, keyword search, sentiment analysis, text summarization, and code conversion.

Also explained in

Compare how 20 books explain ChatGPT →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Starting Data Analytics with Generative AI and Python. The section links point to the parts of the book it draws on.