<jupyter_start><jupyter_text>基本DataFrame操作不同特徵的分布，info()，concat()，loc()，iloc()，describe()，mean()，百分位quantile()，方差var()，標準差std()，value_counts()，<jupyter_code>import pandas as pd
import numpy as np
import os
raw_data_path = os.path.join(os.path.pardir,'data','raw')
train_file_path = os.path.join(os.path.join(raw_data_path,'train.csv'))
test_file_path = os.path.join(os.path.join(raw_data_path,'test.csv'))
train_df = pd.read_csv(train_file_path,index_col='PassengerId')
test_df = pd.read_csv(test_file_path,index_col='PassengerId')
type(train_df)
train_df.info()
test_df.info()
test_df['Survived'] = -888  #adding survived with a default value
df= pd.concat((train_df,test_df),axis=0)
#axis 定義如何連接數據，如果為0，則pandas將逐行連接，
df.info()
df.Name
df['Name']
df[['Name','Age']]
df.loc[5:10]
df.loc[5:10,'Age':'Parch']
#大小寫有區分
df.loc[5:10,['Sex','Age','Parch']]
#位置的索引，可以使用列或行的位置索引，python索引是0開始，使用iloc[]
df.iloc[5:10,7:8]
male_passengers= df.loc[df.Sex=='male']
male_passengers
male_passengers_first_class=df.loc[(df.Sex=='male')| (df.Pclass==1)]
print('number of male passengers : {0}'.format(len(male_passengers_first_class)))
df.Survived
df.describe()

#提取平均值，中心值
print('mean fare {0}'.format(df.Fare.mean()))
print('medin parch {0}'.format(df.Fare.median()))
#提取百分位數
print('百分之25  {0}'.format(df.Fare.quantile(.25)))
print('百分之50  {0}'.format(df.Fare.quantile(.60)))
print('百分之75  {0}'.format(df.Fare.quantile(.75)))
print('方差 {0}'.format(df.Fare.var()))
print('標準差 {0}'.format(df.Fare.std()))
df.Fare.plot(kind='box')
df.describe(include='all')
#計算分類個數
df.Sex.value_counts()
df.Sex.value_counts(normalize=True)
#分類有存活訊息的乘客個數
df[df.Survived != -888].Survived.value_counts()
df.Pclass.value_counts()
df.Pclass.value_counts().plot(kind='box')

df.Pclass.value_counts().plot(kind='bar')
#kind種類長條圖bar，color顏色c，x軸名稱垂直0
df.Pclass.value_counts().plot(kind='bar',rot=0,title='class wise passenger count',color='c');
type(df.Pclass.value_counts())
df.Pclass.plot(kind='bar')
df.Pclass.value_counts().plot()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2099009900990099, 'fraction_numerical': 0.02277227722772277, 'mean_word_length': 9.364102564102565, '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': '626234', 'license': 'MIT', 'n_tokens_mistral': 979, 'n_tokens_neox': 968, 'n_words': 94, 'path': 'notebooks/2020-04-26-exploring-processing-data.ipynb', 'repo_name': 'alane506470/jupyter-exploring-processing-data', 'size': '2020'}