Monday, October 17, 2022

Convert Pandas DataFrame Row or Column to Series

Source:

import pandas as pd    # Create dictionary  students_record = {'Student Names': ['Samreena', 'Raees', 'Asif', 'Affan', 'Idrees', 'Mirha'],         'Physics': [87, 54, 68, 92, 50, 90],         'Chemistry': [78, 58, 85, 82, 76, 71],         'Maths': [90, 88, 50, 89, 77, 80] }    # Converting dictionary to DataFrame  dataframe = pd.DataFrame(data=students_record)    # Display DataFrame  dataframe  # Converting DataFrame row to Series  series = dataframe.iloc[3].reset_index(drop=True).squeeze()    print(series)  print (type(series))

No comments: