pandas dataframe get column by index code example

Example 1: pandas df by row index

indices = [133, 22, 19, 203, 14, 1]
df_by_indices = df.iloc[indices, :]

Example 2: get column index pandas

df = pd.read_csv('thanksgiving_w_age_income.csv')

# Obtain Column Indices:
gravy = df.columns.get_loc("Do you typically have gravy?")
meet_friends = df.columns.get_loc('Have you ever tried to meet up with hometown friends on Thanksgiving night?')
friendsgiving = df.columns.get_loc('Have you ever attended a "Friendsgiving?"')