Create a Dataset with some datas of a csv file

Viewed 28

Good Morning Im trying create a new dataframe with some datas of another dataset (csv file in fact). In the code below, i put df[1] and df[3] because my intention is a new dataset with only these two columns of the csv file(second and forth column) P.S: The original Dataset contains 75 columns **

import pandas as pd

df = pd.read_csv(r'C:\Users\krist\OneDrive\Área de Trabalho\Programação\Python\NFe_E_V3_00626708_20220801_20220830.csv', encoding='latin1', sep=';')


dfreduz = pd.DataFrame(df[1], df[3])

print(dfreduz)
2 Answers

you would need to call the columns by name example:

dfreduz = pd.DataFrame(df["name"], df["job"])

make sure to use quotation marks "

Try this one to select columns based on indexes:

dfreduz =  df.iloc[:, [1, 3]]
Related