0% found this document useful (0 votes)
43 views5 pages

Ml1.ipynb - Colaboratory

The document shows examples of using NumPy and Pandas for data analysis in Python. NumPy is used to create arrays, perform mathematical operations on arrays, and generate random data. Pandas is used to load CSV data into a DataFrame and manipulate the data.

Uploaded by

Lalit jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views5 pages

Ml1.ipynb - Colaboratory

The document shows examples of using NumPy and Pandas for data analysis in Python. NumPy is used to create arrays, perform mathematical operations on arrays, and generate random data. Pandas is used to load CSV data into a DataFrame and manipulate the data.

Uploaded by

Lalit jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

import numpy as np

a= np.array([(1,2,3),(6,7,8),(4,8,6)])
a

array([[1, 2, 3],
[6, 7, 8],
[4, 8, 6]])

a.shape

(3, 3)

a.ndim

a.dtype

output dtype('int64')

b= np.array([(1,2,3),(6,7,8),(3,5,5)])
b

array([[1, 2, 3],
[6, 7, 8],
[3, 5, 5]])

a*b

array([[ 1, 4, 9],
[36, 49, 64],
[12, 40, 30]])

np.matmul(a,b)

array([[ 22, 31, 34],


[ 72, 101, 114],
[ 70, 94, 106]])

a.sum()

45

a.sum(axis=0)

array([11, 17, 17])

a.sum(axis=1)

array([ 6, 21, 18])

a.min()

a.max(axis=0)

array([6, 8, 8])

a.max(axis=1)

array([3, 8, 8])

from numpy import random


x = random.random([3,3])
x

array([[0.5112454 , 0.82549442, 0.91927886],


[0.84097116, 0.74698126, 0.93767599],
[0.91177611, 0.84670274, 0.64887233]])

y = random.randint(5,15, size =[3,3])


y

array([[11, 14, 10],


[ 7, 13, 12],
[13, 9, 5]])

z = np.ones([2,2])
z

array([[1., 1.],
[1., 1.]])

z = np.pad(z, pad_width= 1, mode = 'constant', constant_values=4)


z

array([[4., 4., 4., 4.],


[4., 1., 1., 4.],
[4., 1., 1., 4.],
[4., 4., 4., 4.]])

y[0,1]

import matplotlib
import matplotlib.pyplot as plt
x = [2,4,6]
y = [9,2,1]
plt.plot(x,y)
plt.show()

x1=[1,2,3,4]
y1=[10,20,40,60]
plt.plot(x1,y1,label='First Line')
x2=[4,6,7,9]
y2=[20,30,50,80]
plt.plot(x2,y2,label='Second Line')
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.title('plot the Graph')
plt.legend()
plt.show()
x1=[1,2,3,4]
y1=[5,2,4,6]
x2=[1,3,4,6]
y2=[2,7,5,8]
plt.plot(x1,y1, label = 'First line')
plt.plot(x2,y2, label = 'Second line')
plt.xlabel

import pandas as pd
a =[1,2,3,'machine']
serial = pd.Series(a)
print(serial)

0 1
1 2
2 3
3 machine
dtype: object

data = {"cal" : [100,50,120],


"time": [20,15,35] }
df = pd.DataFrame(data)
print(df)

cal time
0 100 20
1 50 15
2 120 35

df = pd.read_csv('data.csv')
print(df.to_string())

Duration Pulse Maxpulse Calories


0 60 110 130 409.1
1 60 117 145 479.0
2 60 103 135 340.0
3 45 109 175 282.4
4 45 117 148 406.0
5 60 102 127 300.0
6 60 110 136 374.0
7 45 104 134 253.3
8 30 109 133 195.1
9 60 98 124 269.0
10 60 103 147 329.3
11 60 100 120 250.7
12 60 106 128 345.3
13 60 104 132 379.3
14 60 98 123 275.0
15 60 98 120 215.2
16 60 100 120 300.0
17 45 90 112 NaN
18 60 103 123 323.0
19 45 97 125 243.0
20 60 108 131 364.2
21 45 100 119 282.0
22 60 130 101 300.0
23 45 105 132 246.0
24 60 102 126 334.5
25 60 100 120 250.0
26 60 92 118 241.0
27 60 103 132 NaN
28 60 100 132 280.0
29 60 102 129 380.3
30 60 92 115 243.0
31 45 90 112 180.1
32 60 101 124 299.0
33 60 93 113 223.0
34 60 107 136 361.0
35 60 114 140 415.0
36 60 102 127 300.0
37 60 100 120 300.0
38 60 100 120 300.0
39 45 104 129 266.0
40 45 90 112 180.1
41 60 98 126 286.0
42 60 100 122 329.4
43 60 111 138 400.0
44 60 111 131 397.0
45 60 99 119 273.0
46 60 109 153 387.6
47 45 111 136 300.0
48 45 108 129 298.0
49 60 111 139 397.6
50 60 107 136 380.2
51 80 123 146 643.1
52 60 106 130 263.0
53 60 118 151 486.0
54 30 136 175 238.0
55 60 121 146 450.7
0 8 2 3 0
df

Duration Pulse Maxpulse Calories

0 60 110 130 409.1

1 60 117 145 479.0

2 60 103 135 340.0

3 45 109 175 282.4

4 45 117 148 406.0

... ... ... ... ...

164 60 105 140 290.8

165 60 110 145 300.0

166 60 115 145 310.2

167 75 120 150 320.4

168 75 125 150 330.4

169 rows × 4 columns

pd.options.display.max_rows

60

df.shape

(41715, 10)

df.head()
Year Industry_aggregation_NZSIOC Industry_code_NZSIOC Industry_name_NZSIOC Unit

Dolla
0 2021 Level 1 99999 All industries
(million

Dolla
1 2021 Level 1 99999 All industries
(million

Dolla
2 2021 Level 1 99999 All industries
(million

Dolla
3 2021 Level 1 99999 All industries
(million

Dolla
4 2021 Level 1 99999 All industries
(million

df.tail()

Year Industry_aggregation_NZSIOC Industry_code_NZSIOC Industry_name_NZSIOC

Food product
41710 2013 Level 3 ZZ11 Pe
manufacturing

Food product
41711 2013 Level 3 ZZ11 Pe
manufacturing

Food product
41712 2013 Level 3 ZZ11 Pe
manufacturing

Food product
41713 2013 Level 3 ZZ11 Pe
manufacturing

Food product
41714 2013 Level 3 ZZ11 Pe
manufacturing

df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 41715 entries, 0 to 41714
Data columns (total 10 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Year 41715 non-null int64
1 Industry_aggregation_NZSIOC 41715 non-null object
2 Industry_code_NZSIOC 41715 non-null object
3 Industry_name_NZSIOC 41715 non-null object
4 Units 41715 non-null object
5 Variable_code 41715 non-null object
6 Variable_name 41715 non-null object
7 Variable_category 41715 non-null object
8 Value 41715 non-null object
9 Industry_code_ANZSIC06 41715 non-null object
dtypes: int64(1), object(9)
memory usage: 3.2+ MB

You might also like