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)
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]]
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)
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]]