Sie sind auf Seite 1von 3

# 11/5/2019 DVPRACTICE

In [54]:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

In [45]:

## data = {'Name':['Tom', 'nick', 'krish', 'jack','Mogli'],

'Age':[20, 21, 19, 18, 29],
'Height':[143, 167, 173, 188, 111],
'Roll no':[123 ,345, 454, 325, 315]}
df = pd.DataFrame(data)
df
fig, axis = plt.subplots()
axis.scatter(data['Age'],data['Height'])
axis.set_title("Student Dataset")
axis.set_xlabel("Age of student")
axis.set_ylabel("Height of student")

Out[45]:

## QN 1-B Import data from website

In [56]:

url="https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv"

## QN-2A Panda program to add ,subtract, multiple and divide two

panda series

localhost:8889/lab 1/3
11/5/2019 DVPRACTICE

In [47]:

## ds1 = pd.Series([2, 4, 6, 8, 10])

ds2 = pd.Series([1, 3, 5, 7, 9])

ds = ds1 + ds2
print(ds)

ds = ds1 - ds2
print(ds)

ds = ds1 * ds2
print(ds)

## print("Divide Series1 by Series2:")

ds = ds1 / ds2
print(ds)

0 3
1 7
2 11
3 15
4 19
dtype: int64
Subtract two Series:
0 1
1 1
2 1
3 1
4 1
dtype: int64
Multiply two Series:
0 2
1 12
2 30
3 56
4 90
dtype: int64
Divide Series1 by Series2:
0 2.000000
1 1.333333
2 1.200000
3 1.142857
4 1.111111
dtype: float64

## Q-3A FIND error and predict output

localhost:8889/lab 2/3
11/5/2019 DVPRACTICE

In [53]:

## np_array=pd.array([1020, 3040, 50])

print("NumPy array:")
print(np_array)

new_series=pd.Series(np_array)
print(new_series)

NumPy array:
<PandasArray>
[1020, 3040, 50]
Length: 3, dtype: int32
0 1020
1 3040
2 50
dtype: int32

## Q-3B Numpy program to create random 10X4 array and extract

the first five rows of array and store them in variables
In [55]:

import numpy as np
x = np.random.rand(10, 4)
print("Original array: ")
print(x)

y= x[:5, :]
print("First 5 rows of the above array:")
print(y)

Original array:
[[0.17441568 0.23933972 0.97772999 0.68272103]
[0.25317595 0.23504015 0.40021072 0.47302 ]
[0.60089974 0.58026645 0.51411526 0.57915887]
[0.05495293 0.58651941 0.44801079 0.85983661]
[0.33941025 0.47588697 0.14954595 0.07966455]
[0.21186352 0.58056327 0.93948948 0.77414305]
[0.41999973 0.17031088 0.32241843 0.03364639]
[0.21643843 0.30462597 0.23487196 0.08444071]
[0.04537933 0.76077906 0.96465101 0.95429685]
[0.18848946 0.42475939 0.161892 0.68412752]]
First 5 rows of the above array:
[[0.17441568 0.23933972 0.97772999 0.68272103]
[0.25317595 0.23504015 0.40021072 0.47302 ]
[0.60089974 0.58026645 0.51411526 0.57915887]
[0.05495293 0.58651941 0.44801079 0.85983661]
[0.33941025 0.47588697 0.14954595 0.07966455]]

localhost:8889/lab 3/3