E-commerce Using Pandas


Pandas can be useful when you need to create a data frame and access to certain information from a dataset. Pandas can easily read csv and xlsx files. You can even create csv and xlsx files right on Python. Here I am using some transaction data from Amazon to show you how the package works. The dataset is presented below, and it is fictional. 
# Import the Pandas Package
import pandas as pd
# Read in the file as csv
ecom = pd.read_csv('Ecommerce Purchases')

# Find the columns and rows
ecom.info()

This tells us we have a total of 10,000 rows and 14 columns.  To note, in Python, index starts from 0.
# Find the mean, max, and min of purchase price
ecom['Purchase Price'].mean()
ecom['Purchase Price'].max()
ecom['Purchase Price'].min()
Mean: 50.35 Max: 99.99 Min: 0.0
# Find how many people used the English service
ecom[ecom['Language']=='en'].count()
Here we see there are 1098 English users on Amazon in this database. 
# Find out the number of AM and PM purchases 
ecom.groupby('AM or PM')['AM or PM'].count()

There are 4932 customers buying in the AM and 5068 customers buying in the PM. 

I here want to note the difference between count() and value_counts(). They both count up the total for the variable of interest. However, value_counts() sort the data from the highest to the lowest. Here is an example of sorting professions. 
# Using count(), which is not sorted 
ecom.groupby('Job')['Job'].count().head(5)
# Using value_counts(), which is sorted 
ecom['Job'].value_counts().head(5)

Now, based on the sorted 'Job', we found the top five professions above. 

If we want to do something fancy, we can use the apply(). For instance,  we want to find the top 5 email providers in our Amazon database, but before we do that, I want to dissect the solution. 
# First, we want to split the email address at @ by using x.split
ecom['Email'].apply(lambda x: x.split('@')).head(5)
# Only reading the second column to extract all the providers
ecom['Email'].apply(lambda x: x.split('@')[1]).head(5)
# As usual, we count by using value_counts()
ecom['Email'].apply(lambda x: x.split('@')[1]).value_counts().head(5)
Hotmail seems to be the most popular provider in our Amazon database. See how useful is Pandas!

14 comments:

  1. Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important.Project Center in Chennai


    Python Training in Chennai
    Python Training in Chennai
    The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai

    ReplyDelete
  2. Kawaii room decor Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our.

    ReplyDelete
  3. Ecommerce management tools I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

    ReplyDelete
  4. As the owner of an SEO writing company, one of the services I'm questioned about by clients is social media marketing (SMM). Many clients now "get" this form of online marketing, but they may not know which sites best suit their needs. So what usually happens is they'll hire a consultant to set up accounts on all of them. This usually isn't the best strategy by the way. Following are three pieces of advice I dispense to my firm's small business clients about SMM. If you're a freelancer and provide social media account management services, trust me, you'll go a long way towards proving you know your stuff if you advise clients who may be unclear on how to properly "do" this type of web marketing. Marketing Blog

    ReplyDelete
  5. Where to find squishmallows Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me.

    ReplyDelete
  6. wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated. bybit referral code

    ReplyDelete
  7. As the owner of an SEO writing company, one of the services I'm questioned about by clients is social media marketing (SMM). Many clients now "get" this form of online marketing, but they may not know which sites best suit their needs. So what usually happens is they'll hire a consultant to set up accounts on all of them. This usually isn't the best strategy by the way. Following are three pieces of advice I dispense to my firm's small business clients about SMM. If you're a freelancer and provide social media account management services, trust me, you'll go a long way towards proving you know your stuff if you advise clients who may be unclear on how to properly "do" this type of web marketing. Local digital marketing services

    ReplyDelete
  8. buy twitch followers The eyes of parents and the eyes of their children have far different visions when looking for the next hit video game. Insuring that the video games your kids play meet with your expectations while still entertaining them can sometimes be a tricky proposition. We know you're busy - read on to find out how to keep an eye on what your kids are playing without having to become an expert on video games.

    ReplyDelete
  9. https://www.visualaidscentre.com/service/eyes-specialist-delhi/ As the 2008 recession lingers into its fourth year, many consumers have closed their wallets to a long list of "big ticket" purchases, and home improvements appear to be riding the top of that list. With cash reserves at a premium, many home owners have simply decided to wait on making improvements, and understandably so.

    ReplyDelete
  10. https://www.visualaidscentre.com/lasik-eye-surgery-in-delhi/ A long time ago, someone decided that learning games - from the Commodore 64 all the way through to Wii educational games, today - don't need levels, leveling, or the standard video game staple: the end boss. This needs to change.

    ReplyDelete
  11. https://onohosting.com They reality of this situation is realizing that if they damaged any of their original disks they will have to pay the full price to replace their games. Nearly every gamer is worried about this. To better protect your protection and get past this copy protection, every Xbox 360 owners should invest in some game copying software and learn how to burn Xbox 360 games.

    ReplyDelete
  12. seo export This article is for those looking to retain or purchase SEO services. SEO services often times cost thousands of dollars for quality work and the most experienced. It is a daunting task to weed the competent from the incompetent. The article provides you with advice and tips for making the right choice when obtaining SEO services.

    ReplyDelete