What will be the output of the following python code?
import numpy as np
import pandas as pd
array1 = np.array([10,20,30])
array2 = np.array([100,200,300])
array3 = np.array([-10,-20,-30, -40])
dFrame = pd.DataFrame([array1, array3, array2], columns=[ 'A', 'B', 'C', 'D'])
print(dFrame)
What will be the output of the following python code?
import numpy as np
import pandas as pd
array1 = np.array([10,20,30])
array2 = np.array([100,200,300])
array3 = np.array([-10,-20,-30, -40])
dFrame = pd.DataFrame([array1, array3, array2], columns=[ 'A', 'B', 'C', 'D'])
print(dFrame)
Solution
The list passed to the DataFrame is [array1, array3, array2], and each array becomes one row in that order. Row 0 is [10, 20, 30], row 1 is [-10, -20, -30, -40] and row 2 is [100, 200, 300].
The columns are A, B, C, D. The arrays in rows 0 and 2 have only 3 values, so column D is filled with NaN for those rows. Because NaN is a float, column D becomes float, which is why -40 prints as -40.0. Columns A, B and C stay integer.
Option 2: pandas shows missing values as NaN, not Null.
Options 3 and 4: rows follow the order in the list (array1, array3, array2), so array3 must be row 1.
Related questions:
2026: 18 May Shift 2
2026: 21 May Shift 1
2026: 24 May Shift 1
2026: 23 May Shift 1