Using Python Generate an array of 18 odd numbers starting from1. Reshape it to make 3×6 matrix and convert it into data frame.Swap the even number columns with odd number columns and print theresult.
Solution
Code:
import numpy as npimport pandas as pdV = []for i in range(18): V.append(2*i + 1)M = np.asarray(V).reshape((3, 6))df = pd.DataFrame(M)print(df)t = df.copy()for i in range(6): if(i % 2 == 0): df[:][i] = t[:][i + 1] else: df[:][i] = t[:][i – 1]
OR
OR