extract column from dataframe code example
Example 1: pandas iloc select certain columns
dataframe.iloc[:,[1,2]]
Example 2: extract one column from dataframe python
import pandas as pd
input_file = "C:\\....\\consumer_complaints.csv"
dataset = pd.read_csv(input_file)
df = pd.DataFrame(dataset)
cols = [1,2,3,4]
df = df[df.columns[cols]]
Example 3: df only take 2 columns
df1 = df[['a', 'b']]