pandas GET COLUMN code example

Example 1: get column number in dataframe pandas

# PANDAS: get column number from colomn name
dataframe.columns.get_loc("<col_name>")

Example 2: python - subset specific columns name in a dataframe

columns = ['b', 'c']
df1 = pd.DataFrame(df, columns=columns)

Example 3: how to find columns of a dataframe

list(my_dataframe.columns.values)

Example 4: select columns pandas

df1 = df.iloc[:,0:2] # Remember that Python does not slice inclusive of the ending index.

Example 5: get column pandas

column = df["column_name"]