From Prompts to Plots:Visualizing Cricket ๐Ÿ Data

Hi Folks! It has been a while since I wrote my last blog post – was busy with MBA classes and other commitments including a new job role. I could have also told you that I was busy making the visualizations shown in this blog post, but guess what: it only took me about 30 minutes to create this project and less than a minute to create the visualizations, in fact majority of the time was spent on cleaning and preparing the data. And hosted live for anyone to access and with no Power BI or Tableau being used and that was the whole point of it – that can I really create something purely using prompt engineering? The answer is โ€œA STRONG YESโ€.

I have been interested in learning about AI and it is implications and the way it is transforming the world and I decided to do a side project just to play around with it. The only thing that I did myself was a little cleanup of the data and changing some fields and massaging some data and that is where I spent the most time working with.

I wanted to use live source of data for this, however, with the free version of Chat GPT – using API token was off the books so I took that as another challenge that I want to load an excel/csv file for โ€œVirat Kohliโ€™s Centuriesโ€ data that I grabbed from Kaggle.

The other thing that I decided to do was to not use any data visualization toolks like Power BI or Tableau – simply to try to work on it in Python. This was all the preparation that I had to do after which I was ready to just think through and ask the right questions to Chat GPT.

———————————————————————————-

Initially, I explained to it that I am not a Python developer so please explain me everything that is happening and this is the entire code that was generated:

Import necessary libraries

import streamlit as st # for building web apps import pandas as pd # for working with data tables import plotly.express as px # for making interactive charts

Set page configuration: title and layout

st.set_page_config(page_title=”Virat Kohli 100s Analyzer”, layout=”wide”)

Set the main title and subtitle

st.title(“๐Ÿ Virat Kohli 100s โ€” Offline Analyzer”) st.caption(“Explore Kohli’s centuries with filters and charts. No API needed.”)

๐Ÿงพ Upload CSV section

This allows the user to upload the Kohli 100s dataset as a CSV file

data_file = st.file_uploader(“๐Ÿ“ค Upload your ‘Virat_Kohli_100s.csv'”, type=[“csv”])

If the user uploads a file…

if data_file:

Read the CSV file into a Pandas DataFrame (df)

df = pd.read_csv(data_file)

# Show all column names in the file for reference
st.markdown("### ๐Ÿงพ Column Names in File")
st.write(df.columns.tolist())

# If there's no "Year" column, extract year from "Date" column
if "Year" not in df.columns and "Date" in df.columns:
    df["Year"] = pd.to_datetime(df["Date"], errors='coerce').dt.year

# Clean the "Score" column: remove "*" and convert it to a number
df["Score"] = df["Score"].astype(str).str.replace("*", "", regex=False).astype(int)

# Show the full table (raw data)
st.subheader("๐Ÿ“‹ Raw Data Preview")
st.dataframe(df)

# ๐ŸงŠ Sidebar Filters to interact with data
st.sidebar.header("๐Ÿ” Filters")

# Filter by Format (e.g., Test, ODI, IPL, T20I)
formats = st.sidebar.multiselect("Format", df["Format"].unique(), default=df["Format"].unique())

# Filter by Year
years = st.sidebar.multiselect("Year", sorted(df["Year"].dropna().unique()), default=sorted(df["Year"].dropna().unique()))

# Filter by Opponent/Team
opponents = st.sidebar.multiselect("Against", df["Against"].unique(), default=df["Against"].unique())

# Apply filters to create a new DataFrame
filtered_df = df[
    df["Format"].isin(formats) &
    df["Year"].isin(years) &
    df["Against"].isin(opponents)
]

# Show how many records (centuries) matched the filters
st.subheader(f"๐Ÿ“Š Filtered Data โ€” {len(filtered_df)} Centuries")
st.dataframe(filtered_df)

# ๐Ÿงฎ Show Summary Statistics
st.markdown("### ๐Ÿ“ˆ Summary Stats")
col1, col2, col3 = st.columns(3)
col1.metric("Total Centuries", len(filtered_df))  # Total hundreds
col2.metric("Total Score", filtered_df["Score"].sum())  # Total runs from centuries
col3.metric("Average Score", round(filtered_df["Score"].mean(), 2))  # Average score in hundreds

# ๐Ÿ“… Chart: Centuries by Year
st.markdown("### ๐Ÿ“… Centuries by Year")
year_chart = filtered_df.groupby("Year").size().reset_index(name="Centuries")
fig1 = px.bar(year_chart, x="Year", y="Centuries", text="Centuries")
st.plotly_chart(fig1, use_container_width=True)

# ๐ŸŸ๏ธ Chart: Centuries by Opponent
st.markdown("### ๐ŸŸ๏ธ Centuries by Opponent")
opp_chart = filtered_df.groupby("Against").size().reset_index(name="Centuries")
fig2 = px.bar(opp_chart, x="Against", y="Centuries", text="Centuries")
st.plotly_chart(fig2, use_container_width=True)

# ๐Ÿ Chart: Total Score by Format (Pie chart)
st.markdown("### ๐Ÿ Score by Format")
format_chart = filtered_df.groupby("Format")["Score"].sum().reset_index()
fig3 = px.pie(format_chart, names="Format", values="Score", title="Total Score by Format")
st.plotly_chart(fig3, use_container_width=True)

If no file is uploaded, show an info message

else: st.info(“Upload your CSV to get started!”)

———————————————————————————-

This way, I was not only able to generate the code, but was also able to understand each and every step. One thing to note is – I gave Chat GPT the prompt to pick the best visualizations that it thinks are the best. The moment I ran the code – I was pretty surprised. Simply because within 15 seconds, I had a web app (also created using Chat GPT) with all the visualizations built out and it looked simple yet amazing. In Power BI, you can have a public link to share to anyone to view your visualizations and I did not know how to host this web app. And that is when I asked Chat GPT the question and it helped me set it up via steamlit and Github. This is how I was able to get something pretty cool out of prompt engineering via Chat GPT and without writing any code (only running it though, ha!).

Hereโ€™s the link to the WebApp (Please click โ€œWake Upโ€ in case it asks you to):

https://virat100sanalysis-vkyo3aejfkfkrj4rmdjzgt.streamlit.app/

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *