Menu
Coddy logo textTech

Loading Data into a DataFrame

Lesson 3 of 19 in Coddy's Pandas Analytics course.

Usually, when working with data, it is stored in a CSV (Comma Separated Values) file. Every line in this file represents a line, and the first row represents the column names. For example:

 col1,col2,col3
 val1,val2,val3
 val4,val5,val6
 val7,val8,val9

Here we have 3 columns: col1, col2, col3, and 3 rows.

To load a CSV file into a dataframe:

import pandas as pd
df = pd.read_csv('filename.csv')
challenge icon

Challenge

Easy

Create a function named csv_convertor that accepts a file name, loads it into a dataframe, and finally prints the dataframe.

If the CSV file is empty, print "Empty file".

Try it yourself

import pandas as pd
def csv_convertor(filename):
    # Write code here

All lessons in Pandas Analytics