Read Csv file and convert column into list

 Step 1 :- 

Download Csv file from 

https://geocities.ws/ommauryasir/python/data.csv


Step 2 :- 

Write code for  Read.py  :-


# importing the pandas library

import pandas as pd


# reading the csv file using read_csv

# storing the data frame in variable called df

df = pd.read_csv('data.csv')


# creating a list of column names by

# calling the .columns

data = list(df.Calories)


# displaying the list of column names

print(data)


Output:-



and another example :-


import pandas as pd



df = pd.read_csv('list.csv')

data = list(df.phone)




for x in data:
    print(x)
   





Previous
Next Post »