Informatics Practices
What will be the output produced by the following code?
Stationery = ['pencils', 'notebooks', 'scales', 'erasers']
S = pd.Series([20, 33, 52, 10], index = Stationery)
S2 = pd.Series([17, 13, 31, 32], index = Stationery)
print(S == S2)
S = S + S2
print(S)
Python Data Handling
1 Like
Answer
pencils False
notebooks False
scales False
erasers False
dtype: bool
pencils 37
notebooks 46
scales 83
erasers 42
dtype: int64
Working
The code creates two pandas Series, S and S2, with the index Stationery which is a list. The code then compares S and S2 element-wise using the "==" operator, which returns a boolean Series indicating whether each pair of values is equal. Finally, the code adds S and S2 element-wise using the "+" operator, which returns a new Series with the summed values, and assigns the result back to S. The resulting S Series will have the same index as before i.e., Stationery.
Answered By
1 Like
Related Questions
Consider the following tables Item and Customer and answer the questions that follow:
Table: Item
Item_ID ItemName Manufacturer Price PC01 Personal Computer HCL India 42000 LCO5 Laptop HP USA 55000 PCO3 Personal Computer Dell USA 32000 PC06 Personal Computer Zenith USA 37000 LCO3 Laptop Dell USA 57000 Table: Customer
Item_ID CustomerName City LCO3 N Roy Delhi PCO3 H Singh Mumbai PC06 R Pandey Delhi LCO3 C Sharma Chennai PC01 K Agarwal Bengaluru Assume that the Pandas has been imported as pd.
(a) Create a dataframe called dfI for table Item.
(b) Create a dataframe called dfC for table Customer.
(c) Perform the default join operation on item_ID using two dataframes: dfI and dfC.
(d) Perform the left join operation on item_ID using two dataframes: dfI and dfC.
(e) Perform the right join operation on Item_ID using two dataframes: dfI and dfC.
(f) Perform the default operation on Item_ID using two dataframes: dfI and dfC with the left index as true.
(g) Perform the outer join operation on item_ID using two dataframes: dfI and dfC.
(h) Create a new dataframe dfN using dataframes: dfI and dfC. The new dataframe data will hold both left index and right index true values.
(i) Arrange the dataframe dfN in descending order of Price.
(j) Arrange the dataframe dfN in descending order of City and Price.
Consider the following series object namely S:
0 0.430271 1 0.617328 2 0.265421 3 0.836113 dtype: float64What will be returned by the following statements?
(a) S * 100
(b) S > 0
(c) S1 = pd.Series(S)
(d) S3 = pd.Series(S1) + 3
What will be the output produced by the following codes, considering the Series object S given in Q.13?
(a) print(S[1:4])
(b) print(S[:1])
(c) print(S[0:2])
(d) S[0:2] = 12
print(S)(e) print(S.index)
(f) print(S.values)
The Series object 'S' is as follows:
pencils 20 notebooks 33 scales 52 erasers 10 dtype: int64Write a program to iterate and print a dataframe column-wise and print only first three columns.