Advertisements
Advertisements
प्रश्न
Consider the following Python code:
import pandas as pd S1=pd.Series(['Rubina', 'Jaya', 'Vaibhav'], index=[10, 16, 18]) S2=pd.Series(______, index= (10, 16 18]) S3=pd.Series([56, 67, 86], ______) xiia={'Name': ______,'Subject': S2, 'Marks': S3} df=pd.DataFrame (______) print(df)
Complete the above Python code to display the following output:
| Name | Subject | Marks | |
| 10 | Rubina | IP | 56 |
| 16 | Jaya | HSc | 67 |
| 18 | Vaibhav | IP | 86 |
Advertisements
उत्तर
Here's the completed Python code to display the desired output:
import pandas as pd # Create Series objects s1 = pd.Series(['Rubina', 'Jaya', 'Vaibhav'], index=[10, 16, 18)) s2 = pd Series(['IP', 'HSc', 'IP'], index=[10, 16, 18]) s3 = pd.Series([56, 67, 86], index=[10, 16, 18]) # Create a dictionary to hold data for DataFrame xiia = {'Name': s1, 'Subject': s2, 'Marks': s3} # Create DataFrame using the dictionary df = pd.Dataframe(xiia) print(df)
Explanation:
Names, topics, and markings are stored in three Series objects: s1, s2, and s3. Keys are column names, and values are the corresponding series of objects in a dictionary data set. The dictionary data is then used to generate a DataFrame df. The intended result appears when printed.
