Skip to main content

Posts

Showing posts with the label 6.Create a dataframe and print it along with their index using iteritems().

ads1

6.Create a dataframe and print it along with their index using iteritems().

  6.Create a dataframe and print it along with their index using iteritems(). Solution :-  import pandas as pd def df_operations():     sc_4yrs={2016:{'Virat Kohli':2595,'Rohit Sharma':2406,'Shikhar Dhawan':2378},          2017:{'Virat Kohli':2818,'Rohit Sharma':2613,'Shikhar Dhawan':2295},          2018:{'Virat Kohli':2735,'Rohit Sharma':2406,'Shikhar Dhawan':2378},          2019:{'Virat Kohli':2455,'Rohit Sharma':2310,'Shikhar Dhawan':1844}}     df=pd.DataFrame(sc_4yrs)     print(df)     print("------------------------------------------------------------------------")     for (year,runs) in df.iteritems():         print("Year:",year)         print(runs) df_operations() Output :-  

ads2