file = open('moby_dick.txt', mode='r')
print(file.read())
file.close()
print(file.closed) # Check whether file is closed
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
import numpy as np
file = 'digits_header.csv'
d = np.recfromcsv(file, delimiter=',', names=True, dtype=None) # Import file using np.recfromcsv
print(d[:3]) # Print out first three entries of d
import pickle
with open('data.pkl', 'rb') as file: # Open pickle file and load data (read only for a binary file)
d = pickle.load(file)
print(d)
print(type(d))
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_stata('disarea.dta') # Load Stata file into a pandas DataFrame
print(df.head()) # Print the head of the DataFrame
pd.DataFrame.hist(df[['disa10']]) # Plot histogram of one column of the DataFrame
plt.xlabel('Extent of disease')
plt.ylabel('Number of countries')
plt.show()