Column 2. Similarly, df1.iloc[0:3, 0:2] selects the rows from indexes 0 to 2 (both inclusive) and columns 0 to 1 (both inclusive). And as we discussed, loc[] selects rows and columns of a DataFrame by using its labels. And iloc[] selects rows and columns of a DataFrame by using the indexes or rows and columns.
So, the output of the above program will be:
Column 1 Column 2 Column 3 Row 1 1 2 3 Row 2 4 5 6 Row 3 7 8 9 df2: Column 1 Column 2 Row 1 1 2 Row 2 4 5 Row 3 7 8 Type of df2: <class 'pandas.core.frame.DataFrame'> df3: Column 1 Column 2 Row 1 1 2 Row 2 4 5 Row 3 7 8 Type of df3: <class 'pandas.core.frame.DataFrame'>
Please note that both loc[] and iloc[] in this case return pandas DataFrame.






0 Comments