Q. Given a data-frame df as shown below:


import pandas as pd

x = {'speed': [10, 15, 20, 18, 19],\
     'meters': [122, 150, 190, 230, 300],\
     'weight' :[0.2, 0.3, 0.1, 0.85, 0.0]}

df = pd.DataFrame (x)
print (df)

Output :-

   speed  meters  weight
0     10     122    0.20
1     15     150    0.30
2     20     190    0.10
3     18     230    0.85
4     19     300    0.00
>>>

Write code to create scatter graphs from

(a) speed and meters columns of df

(b) meters and weight columns of df


Answer :-

(a)

import pandas as pd
import matplotlib.pyplot as pl

x = {'speed': [10, 15, 20, 18, 19],\
     'meters': [122, 150, 190, 230, 300],\
     'weight' :[0.2, 0.3, 0.1, 0.85, 0.0]}

df = pd.DataFrame (x)
pl.scatter(df['speed'], df [ 'meters'])
pl.show()


Output :-


(b)

import pandas as pd
import matplotlib.pyplot as pl

x = {'speed': [10, 15, 20, 18, 19],\
     'meters': [122, 150, 190, 230, 300],\
     'weight' :[0.2, 0.3, 0.1, 0.85, 0.0]}

df = pd.DataFrame (x)
pl.scatter(df['meters'], df['weight'])
pl.show()


Output :-

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post