# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Reading files and creating data structures

with open("chapter1-1-1.txt", "r") as f:
    data = f.read()

data

data.split(":")

data.split(":")[1]

full_name = data.split(":")[1].strip()
full_name

full_name.split(",")

# method 1
[part.strip() for part in full_name.split(",")]

# method 2
full_name.split(", ")

import json
with open("chapter-1-1-2.json", "r") as f:
    data = f.read()
data

json.loads(data)

type(json.loads(data)), type(json.loads(data)[0])

# # Using data science libraries to import your first dataset

import csv
with open('chapter-1-1-3.csv', newline='') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        print(row['first_name'], row['last_name'])

with open('chapter-1-1-3.csv', newline='') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        print(row)

import pandas as pd

pd.read_csv("chapter-1-1-3.csv")

pd.read_json("chapter-1-1-2.json")

from sklearn.datasets import load_linnerud

dataset = load_linnerud()
dataset.keys()

dataset

dataset = load_linnerud(return_X_y=True)
dataset

from sklearn.datasets import fetch_california_housing
dataset = fetch_california_housing()

dataset["data"].shape

StarcoderdataJupyterScriptsDedupFiltered