#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Janice Cheng

"""
平常列表的结构数据, lst = [11,22,33]
data|11|22|33
index|0|1|2

Series 的结构好像数据库的一张表一样
index|data
0|11
1|22
2|33

第一点: Python的 Series 数据结构接受字典/列表类型的数据，如果用字典的话，字典的键就杷当于 Series的 Index，和Series的Value代表的是数据。
DataFrame 是一种二维的数据结构，非常接近于电子表格或者是类似 MYSQL 数据库的形成

"""
from pandas import Series, DataFrame
import pandas as pd
import sys,os


APP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SRC = os.path.join(APP_DIR+'/src')
sys.path.insert(0,APP_DIR)
sys.path.insert(1,SRC)
marks_file=SRC+'/marks.csv'


# Series
# lst = [11,22,33]
# print(lst)
#
# s = Series(lst)
# print(s)
# print(s.values)
# print(s.index)


s1 = Series([100,'Python','CityU','Janice'], index=['marks','language','university','name'])
# print(s1['name']) # 用字典取数据的方式来获取数据
s1['name'] = 'Ken' # 赋值

data = {'python':90,'scala':85,'java':70}
in1 = ['python','scala','java','go']
s2 = Series(data, in1)
# print(s2)

# 用 pandas 的方式去判断是否为空
# print(pd.isnull(s2))
# print(pd.notnull(s2))

# 用 series 的方式去判断是否为空

#DataFrame
data = {'name':['yahoo','google','facebook'],
        'marks':[200,400,800],
        'price':[9,3,7]}

# df1 = DataFrame(data)
# print(df1)

data = {
        'Animals':['Dog','Bear','Tiger','Moose','Giraffe','Hippopotamus','Mouse'],
        'Owners':['Chris','Kevyn','Bob','Vinod','Daniel','Fil','Stephanie']
}
df = DataFrame(data, columns=['Animals','Owners'])

df2 = DataFrame(data, columns=['name','price','marks']) #固定列的贵序
# print(df2)

df3 = DataFrame(data, columns=['name','price','marks'], index=['a','b','c'])
# print(df3)


df4 = DataFrame(data, columns=['name','price','marks', 'debt'], index=['a','b','c'])
# print(df4['name'])


marks = pd.read_csv(marks_file,sep=",")
# print(marks)
# print(marks.index)
# print(marks.columns)
# print(marks.sort_values(by='english',ascending=False))
print(marks[:1]) #取INDEX的数据，从0开始到