Q. Given :


import pandas as pd


d = {'one' : pd.series([1., 2., 3.], index = ['a', 'b', 'c']), 'two' : pd.series([1., 2., 3., 4.], index = ['a', 'b', 'c', 'd'])}

df = pd.Dataframe(d)

df1 = pd.Dataframe(d, index = ['d', 'b', 'a'])

df2 = pd. Dataframe(d, index = ('d', 'a'), columns = ['two', 'three'])

print(df)

print(df1)

print(df2)


What will Python show the result as if you execute above code?


Answer =

Output :-

   one  two
a  1.0  1.0
b  2.0  2.0
c  3.0  3.0
d  NaN  4.0

   one  two
d  NaN  4.0
b  2.0  2.0
a  1.0  1.0

   two three
d  4.0   NaN
a  1.0   NaN

2 Comments

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

  1. 38. import pandas as pd
    import numpy as np
    kvs = [‘Jetpur’, ‘Junagadh’, ‘Dhoraji’, ‘Rajkot’]
    jtp = pd.dataFrame (pd)
    print (kvs.jtp)
    #Programe is right or will give error ? if it’ll give error how many errors are there ?
    A) No Error, Prog will give output C) 2
    C) 1 D) 3

    ReplyDelete
    Replies
    1. import pandas as pd
      import numpy as np
      kvs = ['Jetpur', 'Junagadh', 'Dhoraji', 'Rajkot’']
      jtp = pd.dataFrame (pd) # to create dataframe the syntax is : DataFram() not dataFrame()
      # to create dataframe we must pass 'list OR dictionary'
      print (kvs.jtp) # variable 'kvs' is a list and 'list' object has no attribute 'jtp'
      # program will give error

      Delete

Post a Comment

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

Previous Post Next Post