![]() |
VOOZH | about |
In this article, we will learn how to slice a DataFrame column-wise in Python. DataFrame is a two-dimensional tabular data structure with labeled axes. i.e. columns.
Output:
Slicing column from 'c' to 'b'.
Output:
The df.loc[] is present in the Pandas package loc can be used to slice a Dataframe using indexing. Pandas DataFrame.loc attribute accesses a group of rows and columns by label(s) or a boolean array in the given DataFrame.
Syntax: [ : , first : last : step]
Example 1:
Slicing column from 'b' to 'd' with step 2.
Output:
Example 2:
Slicing column from 'c' to 'e' with step 1.
Output:
The iloc is present in the Pandas package. The iloc can be used to slice a Dataframe using indexing. df.iloc[] method is used when the index label of a data frame is something other than numeric series of 0, 1, 2, 3β¦.n or in case the user doesnβt know the index label. Rows can be extracted using an imaginary index position that isnβt visible in the data frame.
Syntax: [ start : stop : step]
Example 1:
Slicing column from '1' to '3' with step 1.
Output:
Example 2:
Slicing column from '0' to '3' with step 2.
Output: