<jupyter_start><jupyter_text>汇总和计算描述统计<jupyter_code>df = pd.DataFrame([[1.4,np.nan],
                  [7.1,-4.5],
                  [np.nan,np.nan],
                  [0.75,-1.3]],
                 index=['a','b','c','d'],
                 columns=['one','two'])
df
df.sum()
df.sum(axis=1)
df.mean(axis=1,skipna=False) # skipna 排除缺失值
df.idxmax()
df.cumsum() # 累加
df.describe()
obj = pd.Series(['a','a','b','c']*4)
obj
obj.describe()<jupyter_output><empty_output><jupyter_text>唯一值 值计数和成员资格<jupyter_code>obj = pd.Series(['c','a','d','a','b','b','c','c'])
uniques = obj.unique()
uniques
obj.value_counts()
pd.value_counts(obj.values,sort=False)<jupyter_output><empty_output><jupyter_text>处理缺失值<jupyter_code>string_data = pd.Series(['aardvark','sadfsafasd',np.nan,'avoca'])
string_data
string_data.isnull()
string_data[0] = None
string_data.isnull()<jupyter_output><empty_output><jupyter_text>滤出缺失数据<jupyter_code>from numpy import nan as NA
data = pd.Series([1,NA,3.5,NA,7])
data
data.dropna()
data[data.notnull()]
data = pd.DataFrame([[1.,6.5,3.],
                    [1.,NA,NA],
                    [NA,NA,NA],
                    [NA,6.5,3.]])
cleaned = data.dropna()
data
cleaned
data.dropna(how='all') # 全是NA才扔掉
data.dropna(axis=1,how='all')<jupyter_output><empty_output><jupyter_text>填充缺失数据<jupyter_code>df.fillna(10)<jupyter_output><empty_output><jupyter_text>层次化索引<jupyter_code>data = pd.Series(np.random.randn(10),
                index=[['a','a','a','b','b','b','c','c','d','d'],
                      [1,2,3,1,2,3,1,2,2,3]])
data
data.index
data['b']
data['b':'c']
data.loc[['b','d']]
data.unstack()
data.unstack().stack()<jupyter_output><empty_output><jupyter_text>使用DataFrame的列<jupyter_code>frame = pd.DataFrame({'a':range(7),'b':range(7,0,-1),'c':['one','one','one','two','two','two','two'],'d':[0,1,2,0,1,2,3]})
frame
frame2 = frame.set_index(['c','d'])
frame2
frame.set_index(['c','d'],drop=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.23917525773195877, 'fraction_numerical': 0.028350515463917526, 'mean_word_length': 4.9176829268292686, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '533269', 'license': 'MIT', 'n_tokens_mistral': 875, 'n_tokens_neox': 888, 'n_words': 72, 'path': '05-Machine-Learning-Code/数据分析工具/.ipynb_checkpoints/Day07-checkpoint.ipynb', 'repo_name': 'Lauzanhing/DeepLearning-Is-All-You-Need-Tutorial-', 'size': '1940'}