Page 493 - AI Ver 3.0 class 10_Flipbook
P. 493

6.  Read csv file saved in your system and display 10 rows.


                  Ans.  [1]:  import pandas as pd
                             # Read the CSV file
                             df= pd.read_csv('D:/Data.csv')
                             # Display the first 10 rows with the data heading
                             print(df.head(10))
                                        Name        City
                               0       Aarav       Delhi
                               1       Priya      Mumbai
                               2       Rahul   Bengaluru
                               3        Neha     Chennai
                               4       Arjun     Kolkata
                               5       Sneha   Hyderabad
                               6       Vijay        Pune
                               7  Aishwarya       Jaipur
                               8       Rohit   Ahmedabad
                               9    Deepika        Surat

                   7.  Read csv file saved in your system and display its information.

                  Ans.  [1]:  import pandas as pd
                             # Read the CSV file
                             df= pd.read_csv('D:/Data.csv')
                             print(df)

                                        Name         City
                               0       Aarav        Delhi
                               1       Priya       Mumbai
                               2       Rahul    Bengaluru
                               3        Neha      Chennai
                               4       Arjun      Kolkata
                               5       Sneha    Hyderabad
                               6       Vijay         Pune
                               7  Aishwarya        Jaipur
                               8       Rohit    Ahmedabad
                               9    Deepika         Surat
                              10    Sandeep       Lucknow
                              11        Rani   Chandigarh
                              12       Anand       Bhopal
                              13       Meera        Kochi
                              14       Akash       Indore


                   8.  Write a program to input a string and display the string in the reverse order.

                  Ans.  [1]:  def reverse_string(str):
                                 str1 = ""
                                 for i in str:
                                     str1 = i + str1
                                 return str1
                             str = "ArtificialIntelligence"
                             print("The original string is: ",str)
                             print("The reverse string is",reverse_string(str))

                             The original string is:  ArtificialIntelligence
                             The reverse string is ecnegilletnIlaicifitrA




                                                                                    Python Practical Questions  491
   488   489   490   491   492   493   494   495   496   497   498