-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_code.py
More file actions
59 lines (35 loc) · 1.33 KB
/
python_code.py
File metadata and controls
59 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""python_code.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1HTlsvT7J05SzZcSZzcGAioZZSfb1BASG
"""
import pandas as pd
# Read an Excel file
df = pd.read_excel('company_data.xlsx')
df
df.head(5)
df.tail(5)
df.info()
df.describe()
df['Manufacturer'].value_counts()
df['Product Category'].value_counts()
df['Country'].value_counts()
df[df['Product Name']=='Contoso DVD 9-Inch Player Portable M300 Silver']['Profit']
df[df['Product Name']=='NT Bluetooth Stereo Headphones E52 Pink']['Sales']
df[df['Profit']== df['Profit'].max()]['Product Name']
df[df['Sales']== df['Sales'].max()]['Product Name']
df[df['Sales']== df['Sales'].max()]
df[df['Profit']== df['Profit'].min()]['Product Name']
df[df['Profit']== df['Profit'].min()]
df[df['Sales']== df['Sales'].min()]['Product Name']
# Group data by 'Product Category' and calculate total sales and profits for each category
df.groupby('Product Category').agg({'Sales': 'sum', 'Profit': 'sum'})
# Find the top-selling products
df.groupby('Product Name')['Sales'].sum().nlargest(10)
# Calculate average sales per order
df['Sales'].mean()
# Calculate averag profit per order
df['Profit'].mean()
# Calculate total sales and profit for each region
df.groupby('Region').agg({'Sales': 'sum', 'Profit': 'sum'})