0
Q:

python extract specific columns from pandas dataframe

# Basic syntax:
new_dataframe = dataframe.filter(['col_name_1', 'col_name_2'])
# Where the new_dataframe will only have the column names specified

# Note, use df.filter(['names', ... ], axis=0] to select rows 
1
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]]
1

New to Communities?

Join the community