Informatics Practices
Write a program to create three different Series objects from the three rows of a DataFrame df.
Python Pandas
1 Like
Answer
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
s1 = df.iloc[0]
s2 = df.iloc[1]
s3 = df.iloc[2]
print(s1)
print(s2)
print(s3)Output
A 1
B 4
C 7
Name: 0, dtype: int64
A 2
B 5
C 8
Name: 1, dtype: int64
A 3
B 6
C 9
Name: 2, dtype: int64
Answered By
3 Likes
Related Questions
Write code to print all the information about a Series object.
Write a program to create three different Series objects from the three columns of a DataFrame df.
Write a program to create a Series object from an ndarray that stores characters from 'a' to 'g'.
Write a program to create a Series object that stores the table of number 5.