KnowledgeBoat Logo

Informatics Practices

Predict the output of the given Python code :

import pandas as pd
list1 = [-10, -20, -30]
ser = pd.Series(list1 * 2)
print(ser)

Python Pandas

3 Likes

Answer

0   -10
1   -20
2   -30
3   -10
4   -20
5   -30
dtype: int64

Working

The above code imports the pandas library and assigns it the alias pd. Then, it defines a Python list named list1. The (list1 * 2) expression repeats the list list1 twice. In Python, when we multiply a list by an integer, it creates a new list that contains the original list repeated that number of times. Finally, a Pandas Series object named ser is created from this new list, and the Series ser is printed.

Answered By

1 Like


Related Questions