Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Undergraduate Programme

Submitted By: 2249567


Date Submitted: 01/05/2024 (Self Certification Taken)
Module Title: Programming for Business Applications
Module Code: IB2D40
Date/Year of Module: 2024
Submission Deadline: 24/04/2024
Word Count: 2989
Number of Pages: 17

1
Answer 1 — Source Code (No AI Tool Was Used)
import pandas as pd
import matplotlib.pyplot as plt

# Function to validate user input for file name


# Programming concept 3, 5 and 6 all met with this function
def get_valid_file_name():
while True:
file_name = input("Enter the name of the CSV file: ")
if file_name.endswith('.csv'):
return file_name
else:
print("Please enter a valid CSV file name.")

file_name = get_valid_file_name()

# Read CSV file into a dataframe and display it has been loaded
try:
df = pd.read_csv(file_name)
print("CSV file has been successfully loaded.")

# Define function to plot geographic distribution


def plot_geographic_distribution(data):
region_counts = data['Country Of Origin'].value_counts()
ax = region_counts.plot(kind='bar',
xlabel='Country',
ylabel='Number of Customers',
title='Geographic Distribution',
figsize=(10, 6)) # Increase the figure
size
# Add numeric labels to bars
for i, v in enumerate(region_counts):
ax.text(i, v + 10, str(v), ha='center', va='bottom')
plt.xticks(rotation=45)
plt.tight_layout() # Adjust layout to prevent overlapping
labels
plt.show()

# Define function to plot customer age distribution


def plot_age_distribution(data):
# Define age categories
age_bins = [12, 28, 44, 60, 78, 96]
age_labels = ['Gen Z', 'Millenials', 'Gen X', 'Boomer','Post
War']

# Cut ages into categories


data['Age Category'] = pd.cut(data['Age'], bins=age_bins,
labels=age_labels, right=False)

2
# Count number of customers in each age category
age_category_counts = data['Age Category'].value_counts()

# Sort age categories


age_category_counts = age_category_counts.reindex(age_labels)

# Plot age distribution


ax = age_category_counts.plot(kind='bar', color='green')

# Add numeric labels to bars


for i, v in enumerate(age_category_counts):
ax.text(i, v + 10, str(v), ha='center', va='bottom')
plt.xlabel('Age Category')
plt.ylabel('Number of Customers')
plt.title('Customer Age Distribution')
plt.xticks(rotation=0)
plt.tight_layout()
plt.show()

# Define function to plot fuel type distribution


def plot_fuel_type_distribution(data):
# Clean and preprocess the 'Fuel Type' column since there were
inconsistencies
data['Fuel Type'] = data['Fuel Type'].str.strip().str.lower()

# Count occurrences of each fuel type


fuel_type_counts = data['Fuel Type'].value_counts()

# Plot the fuel type distribution


ax = fuel_type_counts.plot(kind='bar', color='blue')

# Add numeric labels to bars


for i, v in enumerate(fuel_type_counts):
ax.text(i, v + 10, str(v), ha='center', va='bottom')
plt.xlabel('Fuel Type')
plt.ylabel('Number of Cars')
plt.title('Fuel Type Distribution')
plt.xticks(rotation=0)
plt.tight_layout() # Adjust layout to prevent overlapping
labels
plt.show()

# Call the plotting functions


plot_geographic_distribution(df)
plot_fuel_type_distribution(df)
plot_age_distribution(df)

3
except FileNotFoundError:
print("File not found. Please make sure the file exists and try
again.")

Answer 1 — Output

4
Transforming Customer Insights into Actionable Strategies for ‘Next Gen Automotive’
Knowing and understanding customer needs is key and centric to any successful business
model. The entrenchment of this customer-first mentality ensures retaining existing ones
while minimizing the costs of new acquisitions (Charles, 2021). However, before we
anticipate customer needs it is important to gain insights into who the customers are and the
most effective way of making the product available to them (Grow, 2015). The ability to learn
is an organization's only sustainable source of competitive advantage. In practice, this
means the capability of translating data about customers into customer preference and
hence shareholder value (Smith et al., 2006). Therefore, today firms with superior data-to-
value capacity are the ones that lead. As we have established that customer insights are an
integral part of a firm’s brand building process; ‘Next Gen Automotive’ being a small
business can make use of transforming their customer data into actionable insights. The
three key business insights I have generated demonstrate a few ways the company can
derive value from knowing their customers. In addition, the recommendations provided from
the business insights point the business in the right direction to start the process of
segmenting their customer further and targeting them effectively.

1. Business Insight One — Most Customers are in the USA and Germany

Figure 1: Output from the function to plot geographic distribution

The bar graph in Figure 1 illustrates the distribution of customers based on their country of
origin. It is evident that the United States (USA) and Germany stand out as key areas of
opportunity for Next Gen Automotive's long-term growth strategy. This insight is pivotal for
Next Gen as it enables them to identify regions with significant customer concentration,
highlighting areas for potential expansion and investment.

Given that Next Gen is a small business and the need to allocate resources effectively, it
may be worthwhile for the company consider divesting from regions with lower customer
engagement. These regions, including South Africa, Poland, Spain, Switzerland, Bulgaria,
and Sri Lanka, collectively represent less than 0.04% of total sales. By reallocating
resources from these less active markets, Next Gen can focus its efforts on maximizing
returns in regions with greater growth potential.

5
2. Business Insight Two — Most Cars Sold are Petrol based

As can be seen from the bar chart in


Figure 2, most cars purchased by
customers were petrol while alternative
fuel offerings – electric and hybrid, made
up for less than 10% of that figure. In
conjunction to the findings from above
that most of Next Gen’s customers are
from the USA and Germany, we can
derive some actionable insights.

Figure 2: Output from the function to plot fuel distribution


According to a report published by
Potential Energy in 2024, Americans are
some of the most reluctant EV adopters
across the world. In 2022, just 8% of
new cars sold were electric (fully electric
and hybrid) which is far lower than the
global average of 14%. This explains the
domination of petrol fuel type cars in the
analysis. However, based on Figure 3,
from the International Energy Agency in
2023, German Consumers ranked third
among the top electric vehicle adaptors
worldwide in 2022. Figure 3: International Energy Agency. Global EV Outlook 2023

In addition, most Americans think they


will buy an electric car in the next 10 to
15 years. Over a third (37%) expected to
lease or own one in the next five years.
60% in the next 10 years (Potential
Energy Coalition, 2024).

Figure 4
Considering that Next Gen focus on long-term growth within the US and Germany and
based on the insights, it seems that the company should strategically consider expanding its
electric and hybrid car offerings to better align with future consumer preferences, especially
in the US. Given the anticipated shift in the coming years, tapping into this growing demand
could be a lucrative opportunity. Focusing on marketing existing alternative fuel cars in
inventory and their benefits, in Germany where there's already a higher adoption rate, Next
Gen could capture a new customer segment and larger market share. Hence this business
insight is instrumental in recognising a lapse in meeting existing and increasing consumer
needs for electric vehicles in two regions where most of Next Gen’s customers are located.

6
3. Business Insight Three — Most customers are Millennials

Figure 5: Output from the function to plot fuel distribution

The bar graph above segments customers by age and into their respective generations.
More particularly, ages 12-27 have been categorised as Gen Z; 28-43 into Millennials; 44-59
into Gen X; 60-78 into Boomers and 79-96 into Post War (Beresford Research, no date). As
can be seen above in Figure 5, most of Next Gen Automotive’s customers are Millennials
making approximately 40.66% of total customers. This business insight can help Next Gen
segment its customers for targeted marketing strategies. Segmenting customers by age and
generation is crucial for businesses that want to effectively reach and engage with their
target audience. This is because each generation has different needs, preferences, and
behaviours, and a one-size-fits-all approach is not enough in today's competitive
marketplace (Mehta, 2023). Below are some recommendations for targeted marketing
initiatives towards Millennials that the company can make use of.

Studies have shown that 84% of millennials


do not trust traditional advertising methods
and have distrust of brands and
corporations (Jenkins, 2017). Hence
advertising towards Millennials should be
done on platforms that promote
authenticity. These include YouTube,
especially video content and Google My
Business (Jazel Auto Marketing, no date).
Furthermore, the company should conduct
proactive online reputation management on
review sites to build credible, trustworthy,
and good customer reviews. Research by Autotrader Figure 6
in 2016 revealed that Millennials spend over 17 hours researching vehicles before purchase.
This suggest orienting the company’s website to include all details and information on the
vehicle. Integrated tools such as price and feature comparisons between models can also
prove impactful. According to a study by MTV in 2015, 80% of Millennials said that buying or

7
leasing a new car should take less time and 23% of Millennials won’t wait longer than 10
minutes for a test drive. Hence, millennials come from an era of high customer experience
and expect the same. To address the same, Next Gen Automotives should focus on fast
customer service by investing in trained in-store staff and services such as express test
drives and insurance sign ups. Lastly, as seen in Figure 6, 24% of Millennials believe their
generation is unique through their use of technology. Effective integration of in-store and
online channels would hence be appreciated while investment in a Mobile App would ensure
fast and convenient service for the ‘creatures of habit’ that are millennials (Jazel Auto
Marketing, no date).

8
Answer 2 — Source Code (No AI Tool Was Used)
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Read CSV files into dataframes


df1 = pd.read_csv('MoviesData.csv')
df2 = pd.read_csv('MoviesData_new.csv')

# Preprocess dataset by renaming columns and correcting wrong formats


df1_cleaned = df1.rename(columns={"Series_Title": "Title",
"Released_Year": "Release_Year", "Certificate": "Certificate",
"Runtime": "Runtime", "Genre": "Genre", "IMDB Rating": "IMDB_Rating",
"Overview": "Overview"})
df1_cleaned.loc[4, 'Title'] = 'Capernaum'
df1_cleaned.loc[15, 'Release_Year'] = '2018'

# Extract only year from data frame 2 and store it in a similar column
df2['Release_Year'] = pd.to_datetime(df2['Release_Date']).dt.year

# Join DataFrames on the 'Title' column


combined_data = pd.concat([df1_cleaned, df2], ignore_index=True)

# Remove duplicate rows and irrelevant columns


df_final = combined_data.drop(columns={"Certificate",
"Release_Date","Runtime", "IMDB_Rating", "Overview"})
df_final.drop_duplicates(subset='Title', keep='first', inplace=True)

# Split combined genres into individual genres


df_final['Genres'] = df_final['Genre'].str.split(', ')

# Explode the 'Genres' column so that each genre has its own row
df_exploded = df_final.explode('Genres')

# Pivot table to count the number of movies by genre and year


pivot_table = df_exploded.pivot_table(index='Release_Year',
columns='Genres', values='Title', aggfunc='count')

# Reset index to convert index to a column


pivot_table.reset_index(inplace=True)

# Grouping data to get the counts of genres by year


genre_counts_by_year = df_exploded.groupby('Release_Year')
['Genres'].value_counts().unstack().fillna(0).astype(int)

# List of years
years_to_plot = [2018, 2019, 2020, 2021, 2022]

9
# Define a color palette with a unique color for each genre
genre_palette = sns.color_palette('Set3',
n_colors=len(genre_counts_by_year.columns))

# Plot bar chart for each year in the list


for year in years_to_plot:
if year in genre_counts_by_year.index:
ax = genre_counts_by_year.loc[year].plot(kind='bar',
figsize=(10, 6), color=genre_palette)
ax.set_title(f'Number of Movies Released by Genre in {year}')
ax.set_xlabel('Genre')
ax.set_ylabel('Number of Movies')
ax.set_xticklabels(genre_counts_by_year.columns, rotation=45)
# Adding labels above each bar
for i, v in enumerate(genre_counts_by_year.loc[year]):
ax.text(i, v + 0.2, str(v), ha='center', va='bottom')
plt.tight_layout()
plt.show()
else:
print(f"No data available for {year}.")

Answer 2 — Output

Figure 7: Number of Movies Released by Genre in 2018

10
Figure 8: Number of Movies Released by Genre in 2019

Figure 9: Number of Movies Released by Genre in 2020

11
Figure 10: Number of Movies Released by Genre in 2021

Figure 11: Number of Movies Released by Genre in 2022

Answer 2 — Part (i)


To combine the two datasets into one dataset ready for data analysis using Python, I first
read the CSV files into data frames using pandas. Then, I pre-processed the dataset by
renaming columns so that column names could match between both data sets. I also
corrected wrong formats such as data being ‘20188” instead of ‘2018’ in the first data frame.

12
After that, I extracted the year from the second data frame and stored it in a similar column
as the first data frame. This was because the second data frame listed Release Dates in
dd/mm/yy format when I just wanted the year for analysis. Next, I joined the two data frames
on the 'Title' column using the concat() function from pandas. Afterwards, I removed
duplicate rows and irrelevant columns from the combined data frame. Then, I split the
combined genres into individual genres and used the explode function so that each genre
had its own row. Finally, I created a pivot table to count the number of movies by genre and
year. This process involved using various Python libraries such as pandas, seaborn, and
matplotlib.

Answer 2 — Part (ii)


An interesting fact about the release years and genre is that the number of comedy movies
increased from 2018 (6.4% out of total movies) to 2019 (16.1% out of total movies) and then
experienced a drop in 2020 to 10.7%. However, the number of comedy movies started
increasing again in 2021 and 2022 to 12% and 12.5% respectively. While this rise and fall
may seem likely in an industry with multiple genres and rapid shift in audience preferences,
a much larger reason was at play here. The COVID-19 pandemic has been unprecedented
and staggering, with comedy film experiencing higher-than-anticipated demand across all
regions compared to pre-pandemic levels (Business Research Insights, 2024). Many
viewers in times of uncertainty turned to comedy movies and streaming platforms while
staying at home. This is because people craved a sense of escapism from their daily lives
that had become mundane and fearful due to the lockdown. The same trend was also
noticed in stand-up comedy shows that resorted to virtual hosting’s on streaming platforms
(Business Research Insights, 2024).
This key business insight suggests that movie directors and producers can adapt their
content to align with audience preferences during times of global turbulence. As we face
multiple global wars and continuous recessions, by recognizing the increased demand for
comedy movies during challenging times, they can potentially create content that resonates
more strongly with audiences and ensures the profitability of their projects.

Answer 3 — Developing a Feature for a Web Application


Trainline is a British digital rail and coach technology platform operating across Europe. It
sells train tickets and railcards through its website and mobile app which is available on the
iOS and Android platforms (Trainline, no date).

The Feature
The app offers flexible tickets wherein if the specified time for train booked is missed,
customers can take the next trains in the same day. However, the new train they take after
the missed one must meet conditions such as:
 The train must pass through a specific station
 The train must be offered by the same train operator
 The departure and arrival stations must remain the same

Customers who miss their trains must initiate a search on the app again and manually look
for trains that meet the conditions of their missed trains. This can be frustrating and time
consuming while the customer figures out the next best train to travel on. Hence, I suggest a
feature that once the train departs prompts the user to enter whether they have boarded or
not. If they click no, trainline will then suggest them the next best train to take that meets the

13
conditions of their old train (specific above) and recommends the one that takes the shortest
time.
Use of Agile Methodology
To implement this feature using Agile methodology, developers would need to break down
the project into smaller, manageable tasks and iteratively develop and testing them in short
sprints. Potential sprints could include:
1. Gathering Requirements through User Stories and Set Acceptance Criterion (1-2
weeks)
o Work with customer to research pain points through User Stories and detail essential
feature required
o Define conditions and logic to evaluate and suggest the next best train
o Develop an acceptance criterion based on the above and review and prioritise with
product owner and team
2. Designing and Prototyping (2-3 weeks)
o Create mock-ups and wireframes of the user interface
o Develop prototypes for user testing
o Conduct user testing and refine the design and prototype based on user feedback
o Review the changes and design with the product owner and team
3. Development and Testing Against Acceptance Criteria (3-4 weeks)
4. Deployment (1-2 weeks)
o Integrate new feature into the Trainline app, first as a beta testing feature
o Monitor user feedback and usage metrics
o Address issues or bugs arising after deployment
5. Maintenance and Improvement (Ongoing)
o Plan and prioritize future iterations
o Continuously improve based on user feedback and data analysis

The product owner here is responsible for prioritising product backlog (list of features,
requirements, and user stories) and envisions the product and strategy as the voice of the
customer, ensuring the project meets customer’s needs.

Use of Programming Concepts


Here are some programming concepts that can be used to develop the suggested feature:
1. Variables – To store information about trains such as departure and arrival stations, the
station required to pass through, train operator and time. Different data types such as
strings and integers can be used
2. Operators – To manipulate the values within variables such as calculating the duration
of next trains to recommend the fastest one
3. Conditional Statements – To filter trains that meet the conditions of the user’s old train
such as using an if-else statement to check if a train passes through the required station.
Can also be used to ask for and validate user input of whether they boarded the train or
not
4. Loops – To iterate through list of next trains
5. Complex Data Types – Arrays and objects can be used to store the list of next trains
while objects can store information about every train and train station
6. Functions – Make the code more modular by having each block responsible for a
specific action such as sorting or checking if the train meets conditions

14
Business Value for Trainline
Implementing this suggested feature for Trainline would significantly enhance the overall
customer experience by providing a seamless solution to the problem of missed trains.
Additionally, by doing so trainline as a technology platform would be able to display its
commitment to constant innovation and customer satisfaction. The facilitation of automating
the process of finding the next best train would also reduce the burden on customer support,
allowing them to focus on more complex inquiries. Lastly, the feature has great potential to
boost trainline’s sales as it offers them the opportunity to capture customer that might have
been lost due to the inconvenience of manually searching for train alternatives.

15
Reference List
1. Barker, T. (2015). 11 Facts That Will Make You Feel Even More Emotionally Glued To
Your Car. [online] MTV. Available at: https://www.mtv.com/news/31x50f/emotional-bond-
cars-millennials-study [Accessed 1 May 2024].
2. Beresford Research (2024). Age Range by Generation. [online] Beresford Research.
Available at: https://www.beresfordresearch.com/age-range-by-generation/.
3. Business Research Insights (2024). Comedy Film Market Growth, Size, Share and
Forecast [2027]. [online] www.businessresearchinsights.com. Available at:
https://www.businessresearchinsights.com/market-reports/comedy-film-market-108267.
4. Coe, N. (2016). Market Report Auto Trader. [online] Available at:
https://plc.autotrader.co.uk/media/kligt2av/market-report-sept-2016_090916.pdf
[Accessed 30 Apr. 2024].
5. International Energy Agency (2023). Global EV Data Explorer – Data Tools. [online] IEA.
Available at: https://www.iea.org/data-and-statistics/data-tools/global-ev-data-explorer.
6. Jamaal Ewing (2015). The Importance of Knowing Your Customer. [online] Grow.
Available at: https://growbusiness.org/2015/07/the-importance-of-knowing-your-
customer/.
7. Jenkins, T. (2017). The Best Marketing Techniques to Reach Your Millennial Audience.
[online] CBT News. Available at: https://www.cbtnews.com/the-best-marketing-
techniques-to-reach-your-millennial-audience-2/ [Accessed 30 Apr. 2024].
8. Marshall, J., Velasquez-Rose, S., Alcantar, E. and Clay, D. (2024). The Road to Clean
How to message electric vehicles in a charged environment. [online] Available at:
https://potentialenergycoalition.org/wp-content/uploads/2024/03/EV-Report.pdf
[Accessed 30 Apr. 2024].
9. Mehta, J. (2023). The benefits of segmenting customers by age and generation. [online]
abmatic.ai. Available at: https://abmatic.ai/blog/benefits-of-segmenting-customers-by-
age-and-generation#:~:text=Some%20of%20the%20key%20benefits%20of
%20segmenting%20customers%20by%20age [Accessed 30 Apr. 2024].
10. Pew Research Center. (2010). Millennials: Confident. Connected. Open to Change.
[online] Available at: https://www.pewresearch.org/social-trends/2010/02/24/millennials-
confident-connected-open-to-change/#:~:text=Most%20Millennials%20(61%25)%20in
[Accessed 1 May 2024].
11. Ritchie, H. (2024). What do Americans think about electric cars? [online]
www.sustainabilitybynumbers.com. Available at:
https://www.sustainabilitybynumbers.com/p/american-attitudes-ev#footnote-anchor-1-
143703245 [Accessed 30 Apr. 2024].

16
12. Smith, B., Wilson, H. and Clark, M. (2006). Creating and using customer insight: 12
Rules of best practice. Journal of Medical Marketing, 6(2), pp.135–139.
doi:https://doi.org/10.1057/palgrave.jmm.5050013.
13. Tsai, C.-F., Hu, Y.-H. and Lu, Y.-H. (2013). Customer segmentation issues and
strategies for an automobile dealership with two clustering techniques. Expert Systems,
32(1), pp.65–76. doi:https://doi.org/10.1111/exsy.12056.

17

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy