Q. Write a program to print a DataFrame one row at a time and print only first five rows.


Answer :-

import pandas as pd
dict = { 'number' : [1,2,3,4,5,6,7,8] ,'str':['a', 'b', 'c', 'd', 'e','f','g','h']}
df = pd.DataFrame(dict)
print(df.head()) # .head(n) function is used to access the first n rows of a dataframe or series.
                        #Default Value: n=5

Output :-

   number str
0       1   a
1       2   b
2       3   c
3       4   d
4       5   e

>>> 


Post a Comment

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

Previous Post Next Post