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
The python code written below has syntactical errors. Rewrite the correct code and underline the corrections made.
Import pandas as pd df = {"Technology" : ["Programming", "Robotics", "3D Printing"], "Time(in months)" : [4, 4, 3]} df = Pd.dataframe(df) Print(df)
Consider the given SQL string :
"12#All the Best!"
Write suitable SQL queries for the following :
(i) Returns the position of the first occurrence of the substring "the" in the given string.
(ii) To extract last five characters from the string.
Differentiate between the active digital footprint and passive digital footprints.
Complete the given Python code to get the required output as: Rajasthan
import ............... as pd di = { 'Corbett' : 'Uttarakhand', 'Sariska ' : 'Rajasthan', 'Kanha' : 'Madhya Pradesh', 'Gir' : 'Gujarat ' } NP = ............... . Series( ............... ) print(NP[ ............... ])