application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt #collection of command style functions that make matplotlib work

import numpy as np

import pandas as pd

import seaborn as sns #statistical data visualization.

orders_data = pd.read_csv('../input/brazilian-ecommerce/olist_orders_dataset.csv')
payment_data = pd.read_csv('../input/brazilian-ecommerce/olist_order_payments_dataset.csv')
review_data = pd.read_csv('../input/brazilian-ecommerce/olist_order_reviews_dataset.csv')
items_data = pd.read_csv('../input/brazilian-ecommerce/olist_order_items_dataset.csv')
product_data = pd.read_csv('../input/brazilian-ecommerce/olist_products_dataset.csv')
customers_data = pd.read_csv('../input/brazilian-ecommerce/olist_customers_dataset.csv')
sellers_data = pd.read_csv('../input/brazilian-ecommerce/olist_sellers_dataset.csv')
product_trans_data = pd.read_csv('../input/brazilian-ecommerce/product_category_name_translation.csv')
geoloca_data = pd.read_csv('../input/brazilian-ecommerce/olist_geolocation_dataset.csv')

round(orders_data.isnull().sum() / len(orders_data) * 100, 2)

orders_data.order_purchase_timestamp

round(payment_data.isnull().sum() / len(payment_data) * 100, 2)

round(review_data.isnull().sum() / len(review_data) * 100, 2)

round(items_data.isnull().sum() / len(items_data) * 100, 2)

round(product_data.isnull().sum() / len(product_data) * 100, 2)

round(product_data.isnull().sum() / len(product_data) * 100, 2)

round(customers_data.isnull().sum() / len(customers_data) * 100, 2)

round(sellers_data.isnull().sum() / len(sellers_data) * 100, 2)

round(product_trans_data.isnull().sum() / len(product_trans_data) * 100, 2)

orders_data['order_purchase_timestamp'] = pd.to_datetime(orders_data['order_purchase_timestamp'])
orders_data['order_approved_at'] = pd.to_datetime(orders_data['order_approved_at'])
orders_data['order_delivered_carrier_date'] = pd.to_datetime(orders_data['order_delivered_carrier_date'])
orders_data['order_delivered_customer_date'] = pd.to_datetime(orders_data['order_delivered_customer_date'])
orders_data['order_estimated_delivery_date'] = pd.to_datetime(orders_data['order_estimated_delivery_date'])

orders_data_1 = orders_data[orders_data['order_delivered_carrier_date'].notnull()]
miss_carrier = (orders_data_1['order_purchase_timestamp'] - orders_data_1['order_delivered_carrier_date']).mean()
miss_carrier

added_date = orders_data[orders_data['order_delivered_carrier_date'].isnull()]['order_purchase_timestamp'] - miss_carrier
added_date

orders_data['order_delivered_carrier_date'] = orders_data['order_delivered_carrier_date'].replace(np.nan, added_date)
orders_data.isnull().sum()

orders_data.isnull().sum()

orders_data.isnull().sum()

orders_data.dropna(inplace=True)

orders_data.isnull().sum()

review_data.isnull().sum()

review_data.drop(columns=['review_comment_title', 'review_comment_message'], inplace=True)

review_data.isnull().sum()

product_data.dropna(inplace=True)

product_data.isnull().sum()

orders_data.duplicated(['order_id']).sum()

items_data.duplicated(['order_id']).sum()

payment_data.duplicated(['order_id']).sum()

review_data.duplicated(['order_id']).sum()

customers_data.duplicated(['customer_id']).sum()

data_merge = pd.merge(orders_data, items_data, on='order_id', how='inner')
data_merge = pd.merge(data_merge, payment_data, on='order_id', how='inner')
data_merge = pd.merge(data_merge, review_data, on='order_id', how='inner')
data_merge = pd.merge(data_merge, product_data, on='product_id', how='inner')
data_merge = pd.merge(data_merge, customers_data, on='customer_id', how='inner')
data_merge = pd.merge(data_merge, sellers_data, on='seller_id', how='inner')
data_merge = pd.merge(data_merge, product_trans_data, on='product_category_name', how='inner')

Df_ecommerce = data_merge.drop_duplicates(['order_id'])

Df_ecommerce.isnull().sum()

Df_top20prod_rev = Df_ecommerce['price'].groupby(Df_ecommerce['product_category_name_english']).sum().sort_values(ascending=False)[:20]
Df_top20prod_rev

fig=plt.figure(figsize=(16,10))
sns.barplot(y=Df_top20prod_rev.index,x=Df_top20prod_rev.values)
plt.title('Top 20 product category having the largest revenue',fontsize=20)
plt.xlabel('Total revenue',fontsize=17)
plt.ylabel('Product category',fontsize=17)

Df_top20prod_rev