Skip to main content

Posts

Showing posts from 2017
This post covers python topics such as Reading files, Numpy ,Pandas, Matplotlib, Generators and Iterators.









1) Reading Files:We will start with very basic file which is a iris dataset. You can download the file from here https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv
We are going to use to methods for reading files at once here:
1) Read
2) Readlines


Here is the program to read the file:

import time

f=open("/home/amitplatinum/iris.csv",'rb')


##read

start = time.time()
f11=f.read()
end = time.time()
print(end - start)

##readlines

start = time.time()
f12=f.readlines()
end = time.time()
print(end - start)

f.close()

print(f11)

print(f12)

So we have used read() as well as readlines(). Both the functions reads file at once in python. But their are some difference that we should be aware of.
read() function read file into a string object. On the other hand readlines() dump the file into an list object. Both are having advantages and disadvantages. If you want to do …