Read data into pandas

  23 Dec 2018
  python

Provide column names while reading a dataset in pandas

# Import the required modules
import pandas as pd

Reading the dataset using read.csv() function with mentioning column names in names parameters.

#Fetching data from url as csv by mentioning values of various paramters
data = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
                   header = None,
                   index_col = False,
                   names = ['sepal_length','sepal_width','petal_length','petal_width','iris_class'])

Returing the first 10 rows of the dataset using head() function

# Displaying the first ten rows of the data
data.head(n=10)
sepal_lengthsepal_widthpetal_lengthpetal_widthirsi_class
05.13.51.40.2Iris-setosa
14.93.01.40.2Iris-setosa
24.73.21.30.2Iris-setosa
34.63.11.50.2Iris-setosa
45.03.61.40.2Iris-setosa