Super Store Sales Analysis. Analysis of sales data and identify…
By: Katie Huang Xiemin
Tags: Sales Analysis, Python, Data Cleaning, Exploratory Data Analysis, Data Visualisation

Data Exploration

Let’s have a look at the data using df.head() and df.tail() function.

# Preview first 5 rows of data set

superstore.head()

Preview first 5 rows of Super Store data set

# Preview last 5 rows of data set

superstore.tail()

Preview last 5 rows

You can easily tell that there is a mix of categorical, geographical and numerical variables.

Each row represents an order of an item and the corresponding quantity, sales, discount and profit. There is also the mode of shipment, customer segment and geographical aspects.

Next, we will use the df.shape() and df.info() to get more information.

# Shape of data set

superstore.shape (9994, 13) # Summarised information of data set

superstore.info() <class 'pandas.core.frame.DataFrame'>

RangeIndex: 9994 entries, 0 to 9993

Data columns (total 13 columns):

# Column Non-Null Count Dtype

--- ------ -------------- -----

0 Ship Mode 9994 non-null object

1 Segment 9994 non-null object

2 Country 9994 non-null object

3 City 9994 non-null object

4 State 9994 non-null object

5 Postal Code 9994 non-null int64

6 Region 9994 non-null object

7 Category 9994 non-null object

8 Sub-Category 9994 non-null object

9 Sales 9994 non-null float64

10 Quantity 9994 non-null int64

11 Discount 9994 non-null float64

12 Profit 9994 non-null float64

dtypes: float64(3), int64(2), object(8)

memory usage: 1015.1+ KB

There are 9,994 rows including header and 13 columns. Data type is correct and matches the corresponding values.

Data Cleaning

Before we start with the analysis, we must first clean the data or “scrub the dirt”.

For this analysis, we will look at the more common issues such as missing and duplicate data.

Handling Missing Values

Here, we will find out whether there is Null value.

# Find the number of null values for all columns

superstore.isnull().sum() Ship Mode 0

Segment 0

Country 0

City 0

State 0

Postal Code 0

Region 0

Category 0

Sub-Category 0

Sales 0

Quantity 0

Discount 0

Profit 0

dtype: int64

The result shows that the data set does not have any null value.

Duplicate Data

Then, we will find out whether there is duplicate data.

# Find the number of duplicate data

superstore.duplicated().sum() 17

Result shows that there are 17 duplicated rows. Let’s run another function to view the duplicated data.

# Show the duplicated rows

superstore[superstore.duplicated(keep = 'last')]

Preview the 17 duplicated rows

We will then run the drop_duplicates() function to drop the duplicated rows.

# Drop the duplicated rows

superstore.drop_duplicates(inplace = True) # Find the no. of rows and columns

superstore.shape (9977, 13)

Alright! We can confirm that the duplicated rows have been dropped as the rows were 9993 before and now it’s reduced to 9977 rows.

Calculated Field

Now, we will create a calculated field for Profit Margin. The formula is (Profit / Sales) * 100.

superstore['Profit Margin %'] = (superstore.Profit / superstore.Sales) * 100

superstore.head(5)

The new calculated field ‘Profit Margin %’ is added to the last column

Now that the data set has been scrubbed, we can proceed with some statistics analysis!