Giter Site home page Giter Site logo

odd2023-datascience-ex-08's Introduction

Ex-08-Data-Visualization-

AIM

To Perform Data Visualization on the given dataset and save the data to a file.

Explanation

Data visualization is the graphical representation of information and data. By using visual elements like charts, graphs, and maps, data visualization tools provide an accessible way to see and understand trends, outliers, and patterns in data.

ALGORITHM

STEP 1

Read the given Data

STEP 2

Clean the Data Set using Data Cleaning Process

STEP 3

Apply Feature generation and selection techniques to all the features of the data set

STEP 4

Apply data visualization techniques to identify the patterns of the data.

CODE

NAME: Vijay Ganesh N
Register Number : 212221040177
#Import required libraries

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#Load the dataset
df = pd.read_csv('Superstore2.csv', encoding='unicode_escape')
#Data Cleaning: Drop unnecessary columns
df.drop(['Row ID', 'Order ID', 'Ship Date', 'Customer ID', 'Postal Code', 'Product ID'], axis=1, inplace=True)
#Feature Generation: Extract Year and Month from Order Date
df['Year'] = pd.DatetimeIndex(df['Order Date']).year
df['Month'] = pd.DatetimeIndex(df['Order Date']).month_name()

#1. Which Segment has Highest sales?

segment_sales = df.groupby('Segment')['Sales'].sum().reset_index()
plt.figure(figsize=(8,5))
sns.barplot(x='Segment', y='Sales', data=segment_sales)
plt.title('Segment-wise Sales')
plt.show()

#2. Which City has Highest profit?

city_profit = df.groupby('City')['Profit'].sum().reset_index().sort_values(by='Profit', ascending=False)
plt.figure(figsize=(12,8))
sns.barplot(x='City', y='Profit', data=city_profit.head(10))
plt.title('Top 10 Cities by Profit')
plt.show()

#3. Which ship mode is profitable?

shipmode_profit = df.groupby('Ship Mode')['Profit'].sum().reset_index()
plt.figure(figsize=(8,5))
sns.barplot(x='Ship Mode', y='Profit', data=shipmode_profit)
plt.title('Ship Mode-wise Profit')
plt.show()

#4. Sales of the product based on region

region_sales = df.groupby('Region')['Sales'].sum().reset_index()
plt.figure(figsize=(8,5))
sns.barplot(x='Region', y='Sales', data=region_sales)
plt.title('Region-wise Sales')
plt.show()

#5. Find the relation between sales and profit

plt.figure(figsize=(8,5))
sns.scatterplot(x='Sales', y='Profit', data=df)
plt.title('Sales vs. Profit')
plt.show()

#6. Find the relation between sales and profit based on the following category.

#i) Segment

segment_sales_profit = df.groupby('Segment')['Sales', 'Profit'].mean().reset_index()
plt.figure(figsize=(8,5))
sns.barplot(x='Segment', y='Sales', data=segment_sales_profit, color='blue', alpha=0.5, label='Sales')
sns.barplot(x='Segment', y='Profit', data=segment_sales_profit, color='green', alpha=0.5, label='Profit')
plt.title('Segment-wise Sales and Profit')
plt.legend()
plt.show()

#ii) City

city_sales_profit = df.groupby('City')['Sales', 'Profit'].mean().reset_index().sort_values(by='Profit', ascending=False).head(10)
plt.figure(figsize=(12,8))
sns.barplot(x='City', y='Sales', data=city_sales_profit, color='blue', alpha=0.5, label='Sales')
sns.barplot(x='City', y='Profit', data=city_sales_profit, color='green', alpha=0.5, label='Profit')
plt.title('Top 10 Cities by Sales and Profit')
plt.legend()
plt.show()

#iii) States

plt.figure(figsize=(8,5))
sns.scatterplot(x='Sales', y='Profit', hue='State', data=df)
plt.title('Sales vs. Profit based on State')
plt.show()

#iv) Segment and Ship Mode

plt.figure(figsize=(8,5))
sns.scatterplot(x='Sales', y='Profit', hue='Segment', style='Ship Mode', data=df)
plt.title('Sales vs. Profit based on Segment and Ship Mode')
plt.show()

#v) Segment, Ship mode and Region

plt.figure(figsize=(8,5))
sns.scatterplot(x='Sales', y='Profit', hue='Segment', style='Ship Mode', size='Region', data=df)
plt.title('Sales vs. Profit based on Segment, Ship Mode and Region')
plt.show()

OUPUT

image image image image image image image image image image

RESULT:

Hence the data visualization method for the given dataset applied successfully.

odd2023-datascience-ex-08's People

Contributors

karthi-govindharaju avatar bhargava-shankar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.