Home > Back-end >  Creating list from imported CSV file with pandas
Creating list from imported CSV file with pandas

Time:03-23

I am trying to create a list from a CSV. This CSV contains a 2 dimensional table [540 rows and 8 columns] and I would like to create a list that contains the values of an specific column, column 4 to be specific.

I tried: list(df.columns.values)[4], it does mention the name of the column but i'm trying to get the values from the rows on column 4 and make them a list.

import pandas as pd
import urllib
#This is the empty list
company_name = [] 

#Uploading CSV file 
df = pd.read_csv('Downloads\Dropped_Companies.csv')

#Extracting list of all companies name from column "Name of Stock"
companies_column=list(df.columns.values)[4] #This returns the name of the column. 

CodePudding user response:

companies_column = list(df.iloc[:,4].values)

CodePudding user response:

I think that you can try this for getting all the values of a specific column:

companies_column = df[{column name}]

Replace "{column name}" with the column you want to access the values of.

  • Related