Write a program to create three different Series objects from the three rows of a DataFramedf.

Опубликовано: 14 Октябрь 2024
на канале: Portal Express
159
2

Q. Write a program to create three different Series objects from the three rows of a DataFrame df.

Website Link :-
https://www.pathwalla.com/2020/11/wri...

Answer =


import pandas as pd

d={"col1":[1,4,3],"\
col2":[6,7,8],'\
col3':[9,0,1]}

df = pd.DataFrame(d)
s = pd.Series(data=df.iloc[0])
s1 = pd.Series(data=df.iloc[1])
s2 = pd.Series(data=df.iloc[2])


Output :-

col1 1
col2 6
col3 9
Name: 0, dtype: int64

col1 4
col2 7
col3 0
Name: 1, dtype: int64

col1 3
col2 8
col3 1
Name: 2, dtype: int64