<jupyter_start><jupyter_text>範例***  [教學目標]* 能夠使用不同的方法初始化一個陣列* 知道固定大小對於陣列的意義* 了解不同的亂數陣列有什麼差異<jupyter_code># 載入 NumPy, Pandas 套件
import numpy as np
import pandas as pd

# 檢查正確載入與版本
print(np)
print(np.__version__)
print(pd)
print(pd.__version__)
# Series

s = pd.Series([1,2,3])
print(s)
s
s = pd.Series([1,2,3],  index=['Amy', 'Bob', 'Tom'])
print(s)
s
# DataFrame

df = pd.DataFrame([1, 2, 3])
print(df)
df
df = pd.DataFrame([1, 2, 3], index=['a', 'b', 'c'], columns=['No'])
print(df)
df
df = pd.DataFrame([[1, 2, 3], [4, 5, 6]])

print(df)
df
df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], index=['a', 'b'], columns=['A', 'B', 'C'])
print(df)
df
df = pd.DataFrame({
    'Name': ['Alice', 'Bob'],
    'Age': [18, 20],
})
print(df)
df
df = pd.DataFrame([
  {'Name': 'Alice', 'Age': 18},
  {'Name': 'Bob', 'Age': 20}
])
print(df)
df
# DataFrame 是由 Series 组成的

df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], index=['a', 'b'], columns=['A', 'B', 'C'])
print(df['B'])
print(type(df['B']))

# DataFrame 的常用屬性

print(df.shape)
print(df.size)
print(df.index)
print(df.columns)
print(df.values)

# 查看資料

print(df.head())
print(df.tail())
print(df.describe())
print(df.info())<jupyter_output>A  B  C
a  1  2  3
b  4  5  6
   A  B  C
a  1  2  3
b  4  5  6
             A        B        C
count  2.00000  2.00000  2.00000
mean   2.50000  3.50000  4.50000
std    2.12132  2.12132  2.12132
min    1.00000  2.00000  3.00000
25%    1.75000  2.75000  3.75000
50%    2.50000  3.50000  4.50000
75%    3.25000  4.25000  5.25000
max    4.00000  5.00000  6.00000
<class 'pandas.core.frame.DataFrame'>
Index: 2 entries, a to b
Data columns (total 3 columns):
A    2 non-null int64
B    2 non-null int64
C    2 non-null int64
dtypes: int64(3)
memory usage: 64.0+ bytes
None
{'fraction_non_alphanumeric': 0.20069005175388155, 'fraction_numerical': 0.12478435882691202, 'mean_word_length': 3.3828715365239295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '412231', 'license': 'MIT', 'n_tokens_mistral': 985, 'n_tokens_neox': 872, 'n_words': 214, 'path': 'Sample Code/Day_09_SampleCode_v2.ipynb', 'repo_name': 'YenLinWu/DataScienceMarathon', 'size': '1739'}