Create a Dataset with some datas of a csv file

Question:

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:UserskristOneDriveÁrea de TrabalhoProgramaçãoPythonNFe_E_V3_00626708_20220801_20220830.csv', encoding='latin1', sep=';')


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

print(dfreduz)
Asked By: Kristen

||

Answers:

you would need to call the columns by name example:

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

make sure to use quotation marks "

Answered By: Aleks4920

Try this one to select columns based on indexes:

dfreduz =  df.iloc[:, [1, 3]]
Answered By: the_ordinary_guy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.