import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

"""
    Filename and path construction
"""
base_path = os.path.dirname(os.path.abspath(__file__))
titanic_file = base_path + "/Titanic.csv"

"""
    Basic file reading with core python libraries
"""
file = open(titanic_file, mode='r')
content = file.read()
file.close()
# print(content)

with open(titanic_file, mode='r') as file:
    # print(file.read())
    print(file.readlines(5))
    print(file.readline())
    print(file.readline())
    print(file.readline())

#data = pd.read_csv("./sonar_all_data.csv",sep=',')
# print(data)

"""
    Numpy case for numpy arrays usually used with records where all columns share the same type
"""
mnist_file = base_path + "/mnist.csv"
# numeric_data = np.loadtxt(mnist_data, delimiter=',', skiprows=1) #usecols
# print(numeric_data[0])
# print(type(numeric_data))
# print(numeric_data.shape)

"""
    Special case for numpy array with different data types
"""
#mixed_data = np.genfromtxt(titanic_file, delimiter=',', names=True, dtype=None, )
#np.recfromcsv np.recfromtxt defaults delimiter, names, dtype
# print(mixed_data[0:3])
# print(mixed_data.shape)

"""
    PANDAS EXAMPLES
"""
titanic_df = pd.read_csv(titanic_file,sep=',', comment='#', na_values='Nothing')
print(titanic_df.head())

pd.DataFrame.hist(titanic_df[['Age']])
plt.xlabel('Age (years)')
plt.ylabel('Count')
plt.show()