extract specific data from dataframe python code example
Example 1: pandas slicing from one column to another
df.loc[:, 'foo':'cat':2]
df.loc[:, :'bar']
df.loc[:, 'quz'::3]
df.loc[:, 'sat':'bar']
df.loc[:, 'sat':'bar':-1]
sat cat ant quz bar
df.loc[:, slice('quz',None, 2)]
df.loc[:, ['foo','bar','dat']]
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]]