Reading from and writing to files

rstrip and lstrip functions

Removing white blank spaces

How to close the file

If we had typed f = open(path, 'w') then a new file would have been created in place of the old one (thus overwriting the old file). One thus needs to be very careful when using the write command 'w.'

read(i) reads i characthers of the file, seek(i) move curser to the ith charachter in the file, and tell() tells current position in the file.

How to decode the UTF-8 characters characherts of a file

Example

Open in binary mode as follows the file containing symbols like β and Ѳ in the common UTF-8 characters.

In the above output, the 'b' indicates binary. \n shows the end of line. The symbols are given in the UTF-8 characters.

How to convert th binary charachters to utf8

Our line is now in the standard utf8 format. Note that the end of line tag "\n" still remains.

Writing to Files

Here, we read the file1.text to a new file with the name of file4.tex.

The parameters "x", "a", and "w" of the open() method, with one of the following parameters:

"x" - Create - will create a file, returns an error if the file exist

"a" - Append - will create a file if the specified file does not exist

"w" - Write - will create a file if the specified file does not exist

Basic Datasets

Pandas

sudo pip install openpyxl

Reading Data in Pandas

Read headers

Read a specific column

Read a specific row

Sorting/Describing Data

Changing Data

Filtering Data

Conditional Changes

Aggregate Statistic (Groupby)

Working with large amounts of data