a transpose of the resulting DataFrame again. This will reset the indexes of the columns of the original DataFrame.
import pandas list1 = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]] df1 = pandas.DataFrame(list1) print("df1: \n", df1) df1.drop([0, 2], axis=0, inplace=True) df1.drop([1, 2], axis=1, inplace=True) print("df1 after dropping rows and columns: \n", df1) df1.reset_index(drop=True, inplace=True) print("df1 after resetting indexes of rows: \n", df1) df2 = df1.T.reset_index(drop=True, inplace=False).T print("DataFrame after resetting indexes of rows and columns: \n", df2)
So, we are first transposing the df1 DataFrame using df1.T. After that, we are resetting the indexes of the rows of the transposed DataFrame using df1.T.reset_index(drop=True, inplace=False). And then, we are again taking a transpose of the resulting DataFrame using df1.T.reset_index(drop=True, inplace=False).T. Please note that here we are creating a new DataFrame after resetting the indexes. So, the inplace parameter is False here.
The output of the above program will be:
df1: 0 1 2 3 4 0 1 2 3 4 5 1 6 7 8 9 10 2 11 12 13 14 15 3 16 17 18 19 20 df1 after dropping rows and columns: 0 3 4 1 6 9 10 3 16 19 20 df1 after resetting indexes of rows: 0 3 4 0 6 9 10 1 16 19 20 DataFrame after resetting indexes of rows and columns: 0 1 2 0 6 9 10 1 16 19 20






0 Comments