Package: ecommercetools
EcommerceToolsEcommerceTools is a data science toolkit for those working in technical ecommerce, marketing science, and technical seo and includes a wide range of features to aid analysis and model building. The package is written in Python and is designed to be used with Pandas and works within a Jupyter notebook environment or in standalone Python projects.InstallationYou can install EcommerceTools and its dependencies via PyPi by enteringpip3 install ecommercetoolsin your terminal, or!pip3 install ecommercetoolswithin a Jupyter notebook cell.ModulesTransactionsProductsCustomersAdvertisingOperationsMarketingNLPSEOReportsTransactionsLoad sample transaction items dataIf you want to get started with the transactions, products, and customers features, you can use theload_sample_data()function to load a set of real world data. This imports the transaction items from widely-used Online Retail dataset and reformats it ready for use by EcommerceTools.fromecommercetoolsimportutilitiestransaction_items=utilities.load_sample_data()transaction_items.head()order_idskudescriptionquantityorder_dateunit_pricecustomer_idcountryline_price053636585123AWHITE HANGING HEART T-LIGHT HOLDER62010-12-01 08:26:002.5517850.0United Kingdom15.30153636571053WHITE METAL LANTERN62010-12-01 08:26:003.3917850.0United Kingdom20.34253636584406BCREAM CUPID HEARTS COAT HANGER82010-12-01 08:26:002.7517850.0United Kingdom22.00353636584029GKNITTED UNION FLAG HOT WATER BOTTLE62010-12-01 08:26:003.3917850.0United Kingdom20.34453636584029ERED WOOLLY HOTTIE WHITE HEART.62010-12-01 08:26:003.3917850.0United Kingdom20.34Create a transaction items dataframeTheutilitiesmodule includes a range of tools that allow you to format data, so it can be used within other EcommerceTools functions. Theload_transaction_items()function is used to create a Pandas dataframe of formatted transactional item data. When loading your transaction items data, all you need to do is define the column mappings, and the function will reformat the dataframe accordingly.importpandasaspdfromecommercetoolsimportutilitiestransaction_items=utilities.load_transaction_items('transaction_items_non_standard_names.csv',date_column='InvoiceDate',order_id_column='InvoiceNo',customer_id_column='CustomerID',sku_column='StockCode',quantity_column='Quantity',unit_price_column='UnitPrice')transaction_items.to_csv('transaction_items.csv',index=False)print(transaction_items.head())order_idskudescriptionquantityorder_dateunit_pricecustomer_idcountryline_price053636585123AWHITE HANGING HEART T-LIGHT HOLDER62010-12-01 08:26:002.5517850.0United Kingdom15.30153636571053WHITE METAL LANTERN62010-12-01 08:26:003.3917850.0United Kingdom20.34253636584406BCREAM CUPID HEARTS COAT HANGER82010-12-01 08:26:002.7517850.0United Kingdom22.00353636584029GKNITTED UNION FLAG HOT WATER BOTTLE62010-12-01 08:26:003.3917850.0United Kingdom20.34453636584029ERED WOOLLY HOTTIE WHITE HEART.62010-12-01 08:26:003.3917850.0United Kingdom20.34Create a transactions dataframeTheget_transactions()function takes the formatted Pandas dataframe of transaction items and returns a Pandas dataframe of aggregated transaction data, which includes features identifying the order number.importpandasaspdfromecommercetoolsimportcustomerstransaction_items=pd.read_csv('transaction_items.csv')transactions=transactions.get_transactions(transaction_items)transactions.to_csv('transactions.csv',index=False)print(transactions.head())order_idorder_datecustomer_idskusitemsrevenuereplacementorder_number05363652010-12-01 08:26:0017850.0740139.120115363662010-12-01 08:28:0017850.021222.200225363672010-12-01 08:34:0013047.01283278.730135363682010-12-01 08:34:0013047.041570.050245363692010-12-01 08:35:0013047.01317.8503Products1. Get product data from transaction itemsproducts_df=products.get_products(transaction_items)products_df.head()skufirst_order_datelast_order_datecustomersordersitemsrevenueavg_unit_priceavg_quantityavg_revenueavg_ordersproduct_tenureproduct_recency0100022010-12-01 08:45:002011-04-28 15:05:0040731037759.891.05684914.20547910.4094521.82374936001100802011-02-27 13:47:002011-11-21 17:04:001924495119.090.37666720.6250004.9620831.26366033932101202010-12-03 11:19:002011-12-04 13:15:00252919340.530.2100006.4333331.3510001.1637463380310123C2010-12-03 11:19:002011-07-15 15:05:0034-133.250.487500-3.2500000.8125001.3337463522410123G2011-04-08 11:13:002011-04-08 11:13:0001-380.000.000000-38.0000000.000000inf362036202. Calculate product consumption and repurchase raterepurchase_rates=products.get_repurchase_rates(transaction_items)repurchase_rates.head(3).T012sku100021008010120revenue759.89119.0940.53items1037495193orders732429customers401925avg_unit_price1.056850.3766670.21avg_line_price10.40954.962081.351avg_items_per_order14.205520.6256.65517avg_items_per_customer25.92526.05267.72purchased_individually009purchased_once341722bulk_purchases732420bulk_purchase_rate110.689655repurchases3977repurchase_rate0.5342470.2916670.241379repurchase_rate_labelModerate repurchaseLow repurchaseLow repurchasebulk_purchase_rate_labelVery high bulkVery high bulkHigh bulkbulk_and_repurchase_labelModerate repurchase_Very high bulkLow repurchase_Very high bulkLow repurchase_High bulkCustomers1. Create a customers datasetfromecommercetoolsimportcustomerscustomers_df=customers.get_customers(transaction_items)customers_df.head()customer_idrevenueordersskusitemsfirst_order_datelast_order_dateavg_itemsavg_order_valuetenurerecencycohort012346.00.002102011-01-18 10:01:002011-01-18 10:17:000.000.003701370020111112347.04310.007724582010-12-07 14:57:002011-12-07 15:52:00351.14615.713742337720104212348.01797.244423412010-12-16 19:09:002011-09-25 13:13:00585.25449.313733345020104312349.01757.55116312011-11-21 09:51:002011-11-21 09:51:00631.001757.553394339420114412350.0334.40111972011-02-02 16:01:002011-02-02 16:01:00197.00334.4036853685201112. Create a customer cohort analysis datasetfromecommercetoolsimportcustomerscohorts_df=customers.get_cohorts(transaction_items,period='M')cohorts_df.head()customer_idorder_idorder_dateacquisition_cohortorder_cohort017850.05363652010-12-01 08:26:002010-122010-12717850.05363662010-12-01 08:28:002010-122010-12913047.05363672010-12-01 08:34:002010-122010-122113047.05363682010-12-01 08:34:002010-122010-122513047.05363692010-12-01 08:35:002010-122010-123. Create a customer cohort analysis matrixfromecommercetoolsimportcustomerscohort_matrix_df=customers.get_cohort_matrix(transaction_items,period='M',percentage=True)cohort_matrix_df.head()periods0123456789101112acquisition_cohort2010-121.00.3818570.3343880.3871310.3597050.3966240.3797470.3544300.3544300.3945150.3734180.5000000.2742622011-011.00.2399050.2826600.2422800.3277910.2992870.2612830.2565320.3111640.3467930.3681710.149644NaN2011-021.00.2473680.1921050.2789470.2684210.2473680.2552630.2815790.2578950.3131580.092105NaNNaN2011-031.00.1909090.2545450.2181820.2318180.1772730.2636360.2386360.2886360.088636NaNNaNNaN2011-041.00.2274250.2207360.2107020.2073580.2374580.2307690.2608700.083612NaNNaNNaNNaNfromecommercetoolsimportcustomerscohort_matrix_df=customers.get_cohort_matrix(transaction_items,period='M',percentage=False)cohort_matrix_df.head()periods0123456789101112acquisition_cohort2010-12948.0362.0317.0367.0341.0376.0360.0336.0336.0374.0354.0474.0260.02011-01421.0101.0119.0102.0138.0126.0110.0108.0131.0146.0155.063.0NaN2011-02380.094.073.0106.0102.094.097.0107.098.0119.035.0NaNNaN2011-03440.084.0112.096.0102.078.0116.0105.0127.039.0NaNNaNNaN2011-04299.068.066.063.062.071.069.078.025.0NaNNaNNaNNaN4. Create a customer "retention" datasetfromecommercetoolsimportcustomersretention_df=customers.get_retention(transactions_df)retention_df.head()acquisition_cohortorder_cohortcustomersperiods02010-122010-12948012010-122011-01362122010-122011-02317232010-122011-03367342010-122011-0434145. Create an RFM (H) datasetThis is an extension of the regular Recency, Frequency, Monetary value (RFM) model that includes an additional parameter "H" for heterogeneity. This shows the number of unique SKUs purchased by each customer. While typically unassociated with targeting, this value can be very useful in identifying which customers should probably be buying a broader mix of products than they currently are, as well as spotting those who may have stopped buying certain items.fromecommercetoolsimportcustomersrfm_df=customers.get_rfm_segments(customers_df)rfm_df.head()customer_idacquisition_daterecency_daterecencyfrequencymonetaryheterogeneitytenurerfmhrfmrfm_scorerfm_segment_name012346.02011-01-18 10:01:002011-01-18 10:17:00370020.001370111111113Risky112350.02011-02-02 16:01:002011-02-02 16:01:0036851334.401368511111113Risky212365.02011-02-21 13:51:002011-02-21 14:04:0036663320.692366611111113Risky312373.02011-02-01 13:10:002011-02-01 13:10:0036861364.601368611111113Risky412377.02010-12-20 09:37:002011-01-28 15:45:00369021628.122373011111113Risky6. Create a purchase latency datasetfromecommercetoolsimportcustomerslatency_df=customers.get_latency(transactions_df)latency_df.head()customer_idfrequencyrecency_daterecencyavg_latencymin_latencymax_latencystd_latencycvdays_to_next_orderlabel012680.042011-12-09 12:50:00338828167330.8598981.102139-3329.0Order overdue113113.0242011-12-09 12:49:0033881505212.0601260.804008-3361.0Order overdue215804.0132011-12-09 12:31:0033881513911.0082610.733884-3362.0Order overdue313777.0332011-12-09 12:25:0033881104812.0552741.095934-3365.0Order overdue417581.0252011-12-09 12:21:0033881406721.9742931.569592-3352.0Order overdue7. Customer ABC segmentationfromecommercetoolsimportcustomersabc_df=customers.get_abc_segments(customers_df,months=12,abc_class_name='abc_class_12m',abc_rank_name='abc_rank_12m')abc_df.head()customer_idabc_class_12mabc_rank_12m012346.0D1.0112347.0D1.0212348.0D1.0312349.0D1.0412350.0D1.08. Predict customer AOV, CLV, and ordersEcommerceTools allows you to predict the AOV, Customer Lifetime Value (CLV) and expected number of orders via the Gamma-Gamma and BG/NBD models from the excellent Lifetimes package. By passing the dataframe of transactions fromget_transactions()to theget_customer_predictions()function, EcommerceTools will fit the BG/NBD and Gamma-Gamma models and predict the AOV, order quantity, and CLV for each customer in the defined number of future days after the end of the observation period.customer_predictions=customers.get_customer_predictions(transactions_df,observation_period_end='2011-12-09',days=90)customer_predictions.head(10)customer_idpredicted_purchasesaovclv012346.00.188830NaNNaN112347.01.408736569.978836836.846896212348.00.805907333.784235308.247354312349.00.855607NaNNaN412350.00.196304NaNNaN512352.01.682277376.175359647.826169612353.00.272541NaNNaN712354.00.247183NaNNaN812355.00.262909NaNNaN912356.00.645368324.039419256.855226---Advertising1. Create paid search keywordsfromecommercetoolsimportadvertisingproduct_names=['fly rods','fly reels']keywords_prepend=['buy','best','cheap','reduced']keywords_append=['for sale','price','promotion','promo','coupon','voucher','shop','suppliers']campaign_name='fly_fishing'keywords=advertising.generate_ad_keywords(product_names,keywords_prepend,keywords_append,campaign_name)keywords.head()productkeywordsmatch_typecampaign_name0fly rods[fly rods]Exactfly_fishing1fly rods[buy fly rods]Exactfly_fishing2fly rods[best fly rods]Exactfly_fishing3fly rods[cheap fly rods]Exactfly_fishing4fly rods[reduced fly rods]Exactfly_fishing2. Create paid search ad copy using Spintaxfromecommercetoolsimportadvertisingtext="Fly Reels from {Orvis|Loop|Sage|Airflo|Nautilus} for {trout|salmon|grayling|pike}"spin=advertising.generate_spintax(text,single=False)spin['Fly Reels from Orvis for trout',
 'Fly Reels from Orvis for salmon',
 'Fly Reels from Orvis for grayling',
 'Fly Reels from Orvis for pike',
 'Fly Reels from Loop for trout',
 'Fly Reels from Loop for salmon',
 'Fly Reels from Loop for grayling',
 'Fly Reels from Loop for pike',
 'Fly Reels from Sage for trout',
 'Fly Reels from Sage for salmon',
 'Fly Reels from Sage for grayling',
 'Fly Reels from Sage for pike',
 'Fly Reels from Airflo for trout',
 'Fly Reels from Airflo for salmon',
 'Fly Reels from Airflo for grayling',
 'Fly Reels from Airflo for pike',
 'Fly Reels from Nautilus for trout',
 'Fly Reels from Nautilus for salmon',
 'Fly Reels from Nautilus for grayling',
 'Fly Reels from Nautilus for pike']Operations1. Create an ABC inventory classificationinventory_classification=operations.get_inventory_classification(transaction_items)inventory_classification.head()skuabc_classabc_rank010002A1110080A2210120A3310123CA4410123GA4Marketing1. Get ecommerce trading calendarfromecommercetoolsimportmarketingtrading_calendar_df=marketing.get_trading_calendar('2021-01-01',days=365)trading_calendar_df.head()dateevent02021-01-01January sale12021-01-0222021-01-0332021-01-0442021-01-052. Get ecommerce trading eventsfromecommercetoolsimportmarketingtrading_events_df=marketing.get_trading_events('2021-01-01',days=365)trading_events_df.head()dateevent02021-01-01January sale12021-01-29January Pay Day22021-02-11Valentine's Day [last order date]32021-02-14Valentine's Day42021-02-26February Pay DayNLP1. Generate text summariesTheget_summaries()function of thenlpmodule takes a Pandas dataframe containing text and returns a machine-generated summary of the content using a Huggingface Transformers pipeline via PyTorch. To use this feature, first load your Pandas dataframe and import thenlpmodule fromecommercetools.importpandasaspdfromecommercetoolsimportnlppd.set_option('max_colwidth',1000)df=pd.read_csv('text.csv')df.head()Specify the name of the Pandas dataframe, the column containing the text you wish to summarise (i.e.product_description), and specify a column name in which to store the machine-generated summary. Themin_lengthandmax_lengtharguments control the number of words generated, while thedo_sampleargument controls whether the generated text is completely unique (do_sample=False) or extracted from the text (do_sample=True).df=nlp.get_summaries(df,'product_description','sampled_summary',min_length=50,max_length=100,do_sample=True)df=nlp.get_summaries(df,'product_description','unsampled_summary',min_length=50,max_length=100,do_sample=False)df=nlp.get_summaries(df,'product_description','unsampled_summary_20_to_30',min_length=20,max_length=30,do_sample=False)Since the model used for text summarisation is very large (1.2 GB plus), this function will take some time to complete. Once loaded, summaries are generated within a second or two per piece of text, so it is advisable to try smaller volumes of data initially.SEO1. Discover XML sitemap locationsTheget_sitemaps()function takes the location of arobots.txtfile (always stored at the root of a domain), and returns the URLs of any XML sitemaps listed within.fromecommercetoolsimportseositemaps=seo.get_sitemaps("http://www.flyandlure.org/robots.txt")print(sitemaps)2. Get an XML sitemapTheget_dataframe()function allows you to download the URLs in an XML sitemap to a Pandas dataframe. If the sitemap contains child sitemaps, each of these will be retrieved. You can save the Pandas dataframe to CSV in the usual way.fromecommercetoolsimportseodf=seo.get_sitemap("http://flyandlure.org/sitemap.xml")print(df.head())locchangefreqprioritydomainsitemap_name0http://flyandlure.org/hourly1.0flyandlure.orghttp://www.flyandlure.org/sitemap.xml1http://flyandlure.org/aboutmonthly1.0flyandlure.orghttp://www.flyandlure.org/sitemap.xml2http://flyandlure.org/termsmonthly1.0flyandlure.orghttp://www.flyandlure.org/sitemap.xml3http://flyandlure.org/privacymonthly1.0flyandlure.orghttp://www.flyandlure.org/sitemap.xml4http://flyandlure.org/copyrightmonthly1.0flyandlure.orghttp://www.flyandlure.org/sitemap.xml3. Get Core Web Vitals from PageSpeed InsightsTheget_core_web_vitals()function retrieves the Core Web Vitals metrics for a list of sites from the Google PageSpeed Insights API and returns results in a Pandas dataframe. The function requires a a Google PageSpeed Insights API key.fromecommercetoolsimportseopagespeed_insights_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"urls=['https://www.bbc.co.uk','https://www.bbc.co.uk/iplayer']df=seo.get_core_web_vitals(pagespeed_insights_key,urls)print(df.head())4. Get Google Knowledge Graph dataTheget_knowledge_graph()function returns the Google Knowledge Graph data for a given search term. This requires the use of a Google Knowledge Graph API key. By default, the function returns output in a Pandas dataframe, but you can pass theoutput="json"argument if you wish to receive the JSON data back.fromecommercetoolsimportseoknowledge_graph_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"knowledge_graph=seo.get_knowledge_graph(knowledge_graph_key,"tesla",output="dataframe")print(knowledge_graph)5. Get Google Search Console API dataThequery_google_search_console()function runs a search query on the Google Search Console API and returns data in a Pandas dataframe. This function requires a JSON client secrets key with access to the Google Search Console API.fromecommercetoolsimportseokey="google-search-console.json"site_url="http://flyandlure.org"payload={'startDate':"2019-01-01",'endDate':"2019-12-31",'dimensions':["page","device","query"],'rowLimit':100,'startRow':0}df=seo.query_google_search_console(key,site_url,payload)print(df.head())pagedevicequeryclicksimpressionsctrposition0http://flyandlure.org/articles/fly_fishing_gea...MOBILEsimms freestone waders review5621725.813.121http://flyandlure.org/MOBILEfly and lure3715923.273.812http://flyandlure.org/articles/fly_fishing_gea...DESKTOPorvis encounter waders review3513426.124.043http://flyandlure.org/articles/fly_fishing_gea...DESKTOPsimms freestone waders review3520017.503.504http://flyandlure.org/DESKTOPfly and lure3217018.823.09Fetching all results from Google Search ConsoleTo fetch all results, setfetch_alltoTrue. This will automatically paginate through your Google Search Console data and return all results. Be aware that if you do this you may hit Google's quota limit if you run a query over an extended period, or have a busy site with lots ofpageorquerydimensions.fromecommercetoolsimportseokey="google-search-console.json"site_url="http://flyandlure.org"payload={'startDate':"2019-01-01",'endDate':"2019-12-31",'dimensions':["page","device","query"],'rowLimit':25000,'startRow':0}df=seo.query_google_search_console(key,site_url,payload,fetch_all=True)print(df.head())Comparing two time periods in Google Search Consolepayload_before={'startDate':"2021-08-11",'endDate':"2021-08-31",'dimensions':["page","query"],}payload_after={'startDate':"2021-07-21",'endDate':"2021-08-10",'dimensions':["page","query"],}df=seo.query_google_search_console_compare(key,site_url,payload_before,payload_after,fetch_all=False)df.sort_values(by='clicks_change',ascending=False).head()6. Get the number of "indexed" pagesTheget_indexed_pages()function uses the "site:" prefix to search Google for the number of pages "indexed". This is very approximate and may not be a perfect representation, but it's usually a good guide of site "size" in the absence of other data.fromecommercetoolsimportseourls=['https://www.bbc.co.uk','https://www.bbc.co.uk/iplayer','http://flyandlure.org']df=seo.get_indexed_pages(urls)print(df.head())urlindexed_pages2http://flyandlure.org20901https://www.bbc.co.uk/iplayer2150000https://www.bbc.co.uk127000007. Get keyword suggestions from Google AutocompleteThegoogle_autocomplete()function returns a set of keyword suggestions from Google Autocomplete. Theinclude_expanded=Trueargument allows you to expand the number of suggestions shown by appending prefixes and suffixes to the search terms.fromecommercetoolsimportseosuggestions=seo.google_autocomplete("data science",include_expanded=False)print(suggestions)suggestions=seo.google_autocomplete("data science",include_expanded=True)print(suggestions)termrelevance0data science jobs6501data science jobs chester6012data science course6003data science masters5544data science salary5535data science internship5526data science jobs london5517data science graduate scheme5508. Retrieve robots.txt contentTheget_robots()function returns the contents of a robots.txt file in a Pandas dataframe so it can be parsed and analysed.fromecommercetoolsimportseorobots=seo.get_robots("http://www.flyandlure.org/robots.txt")print(robots)directiveparameter0User-agent*1Disallow/signin2Disallow/signup3Disallow/users4Disallow/contact5Disallow/activate6Disallow/*/page7Disallow/articles/search8Disallow/search.php9Disallow*q=*10Disallow*category_slug=*11Disallow*country_slug=*12Disallow*county_slug=*13Disallow*features=*9. Get Google SERPsTheget_serps()function returns a Pandas dataframe containing the Google search engine results for a given search term. Note that this function is not suitable for large-scale scraping and currently includes no features to prevent it from being blocked.fromecommercetoolsimportseoserps=seo.get_serps("data science blog")print(serps)titlelinktext010 of the best data science blogs to follow - ...https://www.tableau.com/learn/articles/data-sc...10 of the best data science blogs to follow. T...1Best Data Science Blogs to Follow in 2020 | by...https://towardsdatascience.com/best-data-scien...14 Jul 2020 — 1. Towards Data Science · Joined...2Top 20 Data Science Blogs And Websites For Dat...https://medium.com/@exastax/top-20-data-scienc...Top 20 Data Science Blogs And Websites For Dat...3Data Science Blog – Dataquesthttps://www.dataquest.io/blog/Browse our data science blog to get helpful ti...451 Awesome Data Science Blogs You Need To Chec...https://365datascience.com/trending/51-data-sc...Blog name: DataKind · datakind data science bl...5Blogs on AI, Analytics, Data Science, Machine ...https://www.kdnuggets.com/websites/blogs.htmlIndividual/small group blogs · Ai4 blog, featu...6Data Science Blog – Applied Data Sciencehttps://data-science-blog.com/... an Bedeutung – DevOps for Data Science. De...7Top 10 Data Science and AI Blogs in 2020 - Liv...https://livecodestream.dev/post/top-data-scien...Some of the best data science and AI blogs for...8Data Science Blogs: 17 Must-Read Blogs for Dat...https://www.thinkful.com/blog/data-science-blogs/Data scientists could be considered the magici...9rushter/data-science-blogs: A curated list of ...https://github.com/rushter/data-science-blogsA curated list of data science blogs. Contribu...To set the domain and host language you can use these parameters. This will search for "bmw" on the German Google domain and return the results in German.df=seo.get_serps("bmw",pages=1,domain="google.de",host_language="de")Create an ABCD classification of Google Search Console dataTheclassify_pages()function returns an ABCD classification of Google Search Console data. This calculates the cumulative sum of clicks and then categorises pages using the ABC algorithm (the first 80% are classed A, the next 10% are classed B, and the final 10% are classed C, with the zero click pages classed D).fromecommercetoolsimportseokey="client_secrets.json"site_url="example-domain.co.uk"start_date='2022-10-01'end_date='2022-10-31'df_classes=seo.classify_pages(key,site_url,start_date,end_date,output='classes')print(df_classes.head())df_summary=seo.classify_pages(key,site_url,start_date,end_date,output='summary')print(df_summary)page  clicks  impressions    ctr  position  clicks_cumsum  clicks_running_pc  pc_share class  class_rank
0  https://practicaldatascience.co.uk/machine-lea...    3890        36577  10.64     12.64           3890           8.382898  8.382898     A           1
1  https://practicaldatascience.co.uk/data-scienc...    2414        16618  14.53     14.30           6304          13.585036  5.202138     A           2
2  https://practicaldatascience.co.uk/data-scienc...    2378        71496   3.33     16.39           8682          18.709594  5.124558     A           3
3  https://practicaldatascience.co.uk/data-scienc...    1942        14274  13.61     15.02          10624          22.894578  4.184984     A           4
4  https://practicaldatascience.co.uk/data-scienc...    1738        23979   7.25     11.80          12362          26.639945  3.745367     A           5


class  pages  impressions  clicks   avg_ctr  avg_position  share_of_clicks  share_of_impressions
0     A     63       747643   36980  5.126349     22.706825             79.7                  43.7
1     B     46       639329    4726  3.228043     31.897826             10.2                  37.4
2     C    190       323385    4698  2.393632     38.259368             10.1                  18.9
3     D     36         1327       0  0.000000     25.804722              0.0                   0.1ReportsThe Reports module creates weekly, monthly, quarterly, or yearly reports for customers and orders and calculates a range of common ecommerce metrics to show business performance.1. Customers reportThecustomers_report()function takes a formatted dataframe of transaction items (see above) and a desired frequency (D for daily, W for weekly, M for monthly, Q for quarterly) and calculates aggregate metrics for each period.The function returns the number of orders, the number of customers, the number of new customers, the number of returning customers, and the acquisition rate (or proportion of new customers). For monthly reporting, I would recommend a 13-month period so you can compare the last month with the same month the previous year.fromecommercetoolsimportreportsdf_customers_report=reports.customers_report(transaction_items,frequency='M')print(df_customers_report.head(13))2. Transactions reportThetransactions_report()function takes a formatted dataframe of transaction items (see above) and a desired frequency (D for daily, W for weekly, M for monthly, Q for quarterly) and calculates aggregate metrics for each period.The metrics returned are: customers, orders, revenue, SKUs, units, average order value, average SKUs per order, average units per order, and average revenue per customer.fromecommercetoolsimportreportsdf_orders_report=reports.transactions_report(transaction_items,frequency='M')print(df_orders_report.head(13))