Page 308 - Ai_C10_Flipbook
P. 308

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




                    306     Artificial Intelligence Play (Ver 1.0)-X
   303   304   305   306   307   308   309   310   311   312   313