Python-100-Days/Day76-90/code/3-pandas数据清洗之空数据.ipynb

6286 lines
180 KiB
Plaintext
Raw Normal View History

2019-05-16 11:59:06 +08:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"import pandas as pd\n",
"\n",
"from pandas import Series,DataFrame"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>122</td>\n",
" <td>10</td>\n",
" <td>5</td>\n",
" <td>28</td>\n",
" <td>57</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>74</td>\n",
" <td>129</td>\n",
" <td>16</td>\n",
" <td>114</td>\n",
" <td>26</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>97</td>\n",
" <td>121</td>\n",
" <td>122</td>\n",
" <td>29</td>\n",
" <td>65</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>141</td>\n",
" <td>73</td>\n",
" <td>120</td>\n",
" <td>147</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>126</td>\n",
" <td>132</td>\n",
" <td>86</td>\n",
" <td>116</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>85</td>\n",
" <td>3</td>\n",
" <td>42</td>\n",
" <td>121</td>\n",
" <td>66</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>142</td>\n",
" <td>65</td>\n",
" <td>1</td>\n",
" <td>124</td>\n",
" <td>83</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>136</td>\n",
" <td>141</td>\n",
" <td>122</td>\n",
" <td>86</td>\n",
" <td>113</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>15</td>\n",
" <td>37</td>\n",
" <td>124</td>\n",
" <td>110</td>\n",
" <td>102</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>63</td>\n",
" <td>30</td>\n",
" <td>44</td>\n",
" <td>69</td>\n",
" <td>58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>59</td>\n",
" <td>38</td>\n",
" <td>113</td>\n",
" <td>109</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>5</td>\n",
" <td>51</td>\n",
" <td>87</td>\n",
" <td>58</td>\n",
" <td>126</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>53</td>\n",
" <td>97</td>\n",
" <td>76</td>\n",
" <td>37</td>\n",
" <td>45</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>42</td>\n",
" <td>148</td>\n",
" <td>107</td>\n",
" <td>97</td>\n",
" <td>143</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>70</td>\n",
" <td>138</td>\n",
" <td>69</td>\n",
" <td>68</td>\n",
" <td>134</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>47</td>\n",
" <td>136</td>\n",
" <td>113</td>\n",
" <td>22</td>\n",
" <td>94</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>31</td>\n",
" <td>137</td>\n",
" <td>6</td>\n",
" <td>20</td>\n",
" <td>28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>148</td>\n",
" <td>74</td>\n",
" <td>134</td>\n",
" <td>4</td>\n",
" <td>124</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>102</td>\n",
" <td>81</td>\n",
" <td>138</td>\n",
" <td>128</td>\n",
" <td>32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>27</td>\n",
" <td>111</td>\n",
" <td>13</td>\n",
" <td>70</td>\n",
" <td>22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>28</td>\n",
" <td>93</td>\n",
" <td>121</td>\n",
" <td>68</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>136</td>\n",
" <td>43</td>\n",
" <td>25</td>\n",
" <td>97</td>\n",
" <td>19</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>111</td>\n",
" <td>70</td>\n",
" <td>12</td>\n",
" <td>38</td>\n",
" <td>58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>96</td>\n",
" <td>103</td>\n",
" <td>147</td>\n",
" <td>86</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" <td>46</td>\n",
" <td>63</td>\n",
" <td>149</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>7</td>\n",
" <td>75</td>\n",
" <td>97</td>\n",
" <td>108</td>\n",
" <td>31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>88</td>\n",
" <td>6</td>\n",
" <td>145</td>\n",
" <td>116</td>\n",
" <td>55</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>33</td>\n",
" <td>74</td>\n",
" <td>106</td>\n",
" <td>50</td>\n",
" <td>46</td>\n",
" </tr>\n",
" <tr>\n",
" <th>128</th>\n",
" <td>74</td>\n",
" <td>28</td>\n",
" <td>26</td>\n",
" <td>100</td>\n",
" <td>76</td>\n",
" </tr>\n",
" <tr>\n",
" <th>129</th>\n",
" <td>76</td>\n",
" <td>18</td>\n",
" <td>101</td>\n",
" <td>126</td>\n",
" <td>133</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>170</th>\n",
" <td>144</td>\n",
" <td>124</td>\n",
" <td>77</td>\n",
" <td>92</td>\n",
" <td>82</td>\n",
" </tr>\n",
" <tr>\n",
" <th>171</th>\n",
" <td>36</td>\n",
" <td>98</td>\n",
" <td>48</td>\n",
" <td>43</td>\n",
" <td>80</td>\n",
" </tr>\n",
" <tr>\n",
" <th>172</th>\n",
" <td>51</td>\n",
" <td>143</td>\n",
" <td>68</td>\n",
" <td>34</td>\n",
" <td>74</td>\n",
" </tr>\n",
" <tr>\n",
" <th>173</th>\n",
" <td>149</td>\n",
" <td>117</td>\n",
" <td>18</td>\n",
" <td>141</td>\n",
" <td>120</td>\n",
" </tr>\n",
" <tr>\n",
" <th>174</th>\n",
" <td>8</td>\n",
" <td>139</td>\n",
" <td>146</td>\n",
" <td>112</td>\n",
" <td>122</td>\n",
" </tr>\n",
" <tr>\n",
" <th>175</th>\n",
" <td>115</td>\n",
" <td>101</td>\n",
" <td>64</td>\n",
" <td>62</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>176</th>\n",
" <td>10</td>\n",
" <td>7</td>\n",
" <td>140</td>\n",
" <td>45</td>\n",
" <td>148</td>\n",
" </tr>\n",
" <tr>\n",
" <th>177</th>\n",
" <td>65</td>\n",
" <td>43</td>\n",
" <td>68</td>\n",
" <td>109</td>\n",
" <td>18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>178</th>\n",
" <td>31</td>\n",
" <td>100</td>\n",
" <td>110</td>\n",
" <td>49</td>\n",
" <td>123</td>\n",
" </tr>\n",
" <tr>\n",
" <th>179</th>\n",
" <td>29</td>\n",
" <td>46</td>\n",
" <td>69</td>\n",
" <td>57</td>\n",
" <td>90</td>\n",
" </tr>\n",
" <tr>\n",
" <th>180</th>\n",
" <td>146</td>\n",
" <td>86</td>\n",
" <td>18</td>\n",
" <td>22</td>\n",
" <td>46</td>\n",
" </tr>\n",
" <tr>\n",
" <th>181</th>\n",
" <td>71</td>\n",
" <td>50</td>\n",
" <td>40</td>\n",
" <td>90</td>\n",
" <td>140</td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>4</td>\n",
" <td>100</td>\n",
" <td>147</td>\n",
" <td>116</td>\n",
" <td>110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>183</th>\n",
" <td>55</td>\n",
" <td>87</td>\n",
" <td>93</td>\n",
" <td>78</td>\n",
" <td>34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>184</th>\n",
" <td>5</td>\n",
" <td>109</td>\n",
" <td>124</td>\n",
" <td>87</td>\n",
" <td>82</td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>10</td>\n",
" <td>118</td>\n",
" <td>139</td>\n",
" <td>50</td>\n",
" <td>51</td>\n",
" </tr>\n",
" <tr>\n",
" <th>186</th>\n",
" <td>32</td>\n",
" <td>12</td>\n",
" <td>71</td>\n",
" <td>36</td>\n",
" <td>124</td>\n",
" </tr>\n",
" <tr>\n",
" <th>187</th>\n",
" <td>94</td>\n",
" <td>16</td>\n",
" <td>138</td>\n",
" <td>13</td>\n",
" <td>149</td>\n",
" </tr>\n",
" <tr>\n",
" <th>188</th>\n",
" <td>65</td>\n",
" <td>101</td>\n",
" <td>123</td>\n",
" <td>128</td>\n",
" <td>86</td>\n",
" </tr>\n",
" <tr>\n",
" <th>189</th>\n",
" <td>43</td>\n",
" <td>94</td>\n",
" <td>10</td>\n",
" <td>29</td>\n",
" <td>132</td>\n",
" </tr>\n",
" <tr>\n",
" <th>190</th>\n",
" <td>68</td>\n",
" <td>135</td>\n",
" <td>94</td>\n",
" <td>28</td>\n",
" <td>125</td>\n",
" </tr>\n",
" <tr>\n",
" <th>191</th>\n",
" <td>30</td>\n",
" <td>60</td>\n",
" <td>98</td>\n",
" <td>27</td>\n",
" <td>15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>192</th>\n",
" <td>89</td>\n",
" <td>16</td>\n",
" <td>10</td>\n",
" <td>135</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>193</th>\n",
" <td>104</td>\n",
" <td>139</td>\n",
" <td>97</td>\n",
" <td>29</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>194</th>\n",
" <td>5</td>\n",
" <td>29</td>\n",
" <td>41</td>\n",
" <td>99</td>\n",
" <td>91</td>\n",
" </tr>\n",
" <tr>\n",
" <th>195</th>\n",
" <td>19</td>\n",
" <td>102</td>\n",
" <td>135</td>\n",
" <td>41</td>\n",
" <td>40</td>\n",
" </tr>\n",
" <tr>\n",
" <th>196</th>\n",
" <td>58</td>\n",
" <td>100</td>\n",
" <td>70</td>\n",
" <td>82</td>\n",
" <td>64</td>\n",
" </tr>\n",
" <tr>\n",
" <th>197</th>\n",
" <td>84</td>\n",
" <td>97</td>\n",
" <td>129</td>\n",
" <td>76</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>131</td>\n",
" <td>15</td>\n",
" <td>7</td>\n",
" <td>44</td>\n",
" <td>114</td>\n",
" </tr>\n",
" <tr>\n",
" <th>199</th>\n",
" <td>79</td>\n",
" <td>37</td>\n",
" <td>95</td>\n",
" <td>128</td>\n",
" <td>116</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 122 10 5 28 57\n",
"101 74 129 16 114 26\n",
"102 97 121 122 29 65\n",
"103 141 73 120 147 1\n",
"104 126 132 86 116 17\n",
"105 85 3 42 121 66\n",
"106 142 65 1 124 83\n",
"107 136 141 122 86 113\n",
"108 15 37 124 110 102\n",
"109 63 30 44 69 58\n",
"110 59 38 113 109 16\n",
"111 5 51 87 58 126\n",
"112 53 97 76 37 45\n",
"113 42 148 107 97 143\n",
"114 70 138 69 68 134\n",
"115 47 136 113 22 94\n",
"116 31 137 6 20 28\n",
"117 148 74 134 4 124\n",
"118 102 81 138 128 32\n",
"119 27 111 13 70 22\n",
"120 28 93 121 68 4\n",
"121 136 43 25 97 19\n",
"122 111 70 12 38 58\n",
"123 96 103 147 86 8\n",
"124 10 10 46 63 149\n",
"125 7 75 97 108 31\n",
"126 88 6 145 116 55\n",
"127 33 74 106 50 46\n",
"128 74 28 26 100 76\n",
"129 76 18 101 126 133\n",
".. ... ... ... ... ...\n",
"170 144 124 77 92 82\n",
"171 36 98 48 43 80\n",
"172 51 143 68 34 74\n",
"173 149 117 18 141 120\n",
"174 8 139 146 112 122\n",
"175 115 101 64 62 9\n",
"176 10 7 140 45 148\n",
"177 65 43 68 109 18\n",
"178 31 100 110 49 123\n",
"179 29 46 69 57 90\n",
"180 146 86 18 22 46\n",
"181 71 50 40 90 140\n",
"182 4 100 147 116 110\n",
"183 55 87 93 78 34\n",
"184 5 109 124 87 82\n",
"185 10 118 139 50 51\n",
"186 32 12 71 36 124\n",
"187 94 16 138 13 149\n",
"188 65 101 123 128 86\n",
"189 43 94 10 29 132\n",
"190 68 135 94 28 125\n",
"191 30 60 98 27 15\n",
"192 89 16 10 135 4\n",
"193 104 139 97 29 17\n",
"194 5 29 41 99 91\n",
"195 19 102 135 41 40\n",
"196 58 100 70 82 64\n",
"197 84 97 129 76 13\n",
"198 131 15 7 44 114\n",
"199 79 37 95 128 116\n",
"\n",
"[100 rows x 5 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = DataFrame(np.random.randint(0,150,size = (100,5)),index = np.arange(100,200),columns=['Python','En','Math','Physic','Chem'])\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python False\n",
"En False\n",
"Math False\n",
"Physic False\n",
"Chem False\n",
"dtype: bool"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 判断DataFrame是否存在空数据\n",
"df.isnull().any()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python True\n",
"En True\n",
"Math True\n",
"Physic True\n",
"Chem True\n",
"dtype: bool"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.notnull().all()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"500"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"100*5"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"for i in range(50):\n",
" # 行索引\n",
" index = np.random.randint(100,200,size =1)[0]\n",
"\n",
" cols = df.columns\n",
"\n",
" # 列索引\n",
" col = np.random.choice(cols)\n",
"\n",
" df.loc[index,col] = None"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"for i in range(20):\n",
" # 行索引\n",
" index = np.random.randint(100,200,size =1)[0]\n",
"\n",
" cols = df.columns\n",
"\n",
" # 列索引\n",
" col = np.random.choice(cols)\n",
"\n",
"# not a number 不是一个数\n",
" df.loc[index,col] = np.NAN"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>122.0</td>\n",
" <td>10.0</td>\n",
" <td>5.0</td>\n",
" <td>28.0</td>\n",
" <td>57.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>NaN</td>\n",
" <td>129.0</td>\n",
" <td>16.0</td>\n",
" <td>114.0</td>\n",
" <td>26.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>97.0</td>\n",
" <td>121.0</td>\n",
" <td>122.0</td>\n",
" <td>29.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>141.0</td>\n",
" <td>73.0</td>\n",
" <td>120.0</td>\n",
" <td>147.0</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>126.0</td>\n",
" <td>NaN</td>\n",
" <td>86.0</td>\n",
" <td>116.0</td>\n",
" <td>17.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>85.0</td>\n",
" <td>NaN</td>\n",
" <td>42.0</td>\n",
" <td>121.0</td>\n",
" <td>66.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>142.0</td>\n",
" <td>65.0</td>\n",
" <td>1.0</td>\n",
" <td>124.0</td>\n",
" <td>83.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>136.0</td>\n",
" <td>141.0</td>\n",
" <td>NaN</td>\n",
" <td>86.0</td>\n",
" <td>113.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>15.0</td>\n",
" <td>37.0</td>\n",
" <td>124.0</td>\n",
" <td>110.0</td>\n",
" <td>102.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>63.0</td>\n",
" <td>30.0</td>\n",
" <td>NaN</td>\n",
" <td>69.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>113.0</td>\n",
" <td>109.0</td>\n",
" <td>16.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>5.0</td>\n",
" <td>51.0</td>\n",
" <td>87.0</td>\n",
" <td>58.0</td>\n",
" <td>126.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>53.0</td>\n",
" <td>97.0</td>\n",
" <td>76.0</td>\n",
" <td>37.0</td>\n",
" <td>45.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>42.0</td>\n",
" <td>148.0</td>\n",
" <td>NaN</td>\n",
" <td>97.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>70.0</td>\n",
" <td>138.0</td>\n",
" <td>69.0</td>\n",
" <td>68.0</td>\n",
" <td>134.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>NaN</td>\n",
" <td>136.0</td>\n",
" <td>113.0</td>\n",
" <td>22.0</td>\n",
" <td>94.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>31.0</td>\n",
" <td>137.0</td>\n",
" <td>6.0</td>\n",
" <td>20.0</td>\n",
" <td>28.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>148.0</td>\n",
" <td>74.0</td>\n",
" <td>134.0</td>\n",
" <td>4.0</td>\n",
" <td>124.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>102.0</td>\n",
" <td>81.0</td>\n",
" <td>138.0</td>\n",
" <td>128.0</td>\n",
" <td>32.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>27.0</td>\n",
" <td>111.0</td>\n",
" <td>13.0</td>\n",
" <td>NaN</td>\n",
" <td>22.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>28.0</td>\n",
" <td>93.0</td>\n",
" <td>121.0</td>\n",
" <td>NaN</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>136.0</td>\n",
" <td>NaN</td>\n",
" <td>25.0</td>\n",
" <td>97.0</td>\n",
" <td>19.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>111.0</td>\n",
" <td>70.0</td>\n",
" <td>12.0</td>\n",
" <td>38.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>NaN</td>\n",
" <td>103.0</td>\n",
" <td>147.0</td>\n",
" <td>86.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>10.0</td>\n",
" <td>10.0</td>\n",
" <td>46.0</td>\n",
" <td>63.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>7.0</td>\n",
" <td>75.0</td>\n",
" <td>97.0</td>\n",
" <td>108.0</td>\n",
" <td>31.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>88.0</td>\n",
" <td>6.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>55.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>33.0</td>\n",
" <td>74.0</td>\n",
" <td>106.0</td>\n",
" <td>50.0</td>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>128</th>\n",
" <td>74.0</td>\n",
" <td>28.0</td>\n",
" <td>26.0</td>\n",
" <td>100.0</td>\n",
" <td>76.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>129</th>\n",
" <td>76.0</td>\n",
" <td>18.0</td>\n",
" <td>101.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>170</th>\n",
" <td>144.0</td>\n",
" <td>124.0</td>\n",
" <td>77.0</td>\n",
" <td>92.0</td>\n",
" <td>82.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>171</th>\n",
" <td>36.0</td>\n",
" <td>98.0</td>\n",
" <td>NaN</td>\n",
" <td>43.0</td>\n",
" <td>80.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>172</th>\n",
" <td>51.0</td>\n",
" <td>NaN</td>\n",
" <td>68.0</td>\n",
" <td>34.0</td>\n",
" <td>74.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>173</th>\n",
" <td>149.0</td>\n",
" <td>NaN</td>\n",
" <td>18.0</td>\n",
" <td>141.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>174</th>\n",
" <td>8.0</td>\n",
" <td>139.0</td>\n",
" <td>146.0</td>\n",
" <td>112.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>175</th>\n",
" <td>115.0</td>\n",
" <td>NaN</td>\n",
" <td>64.0</td>\n",
" <td>62.0</td>\n",
" <td>9.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>176</th>\n",
" <td>NaN</td>\n",
" <td>7.0</td>\n",
" <td>140.0</td>\n",
" <td>45.0</td>\n",
" <td>148.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>177</th>\n",
" <td>NaN</td>\n",
" <td>43.0</td>\n",
" <td>68.0</td>\n",
" <td>109.0</td>\n",
" <td>18.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>178</th>\n",
" <td>31.0</td>\n",
" <td>100.0</td>\n",
" <td>NaN</td>\n",
" <td>49.0</td>\n",
" <td>123.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>179</th>\n",
" <td>29.0</td>\n",
" <td>46.0</td>\n",
" <td>69.0</td>\n",
" <td>57.0</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>180</th>\n",
" <td>146.0</td>\n",
" <td>86.0</td>\n",
" <td>18.0</td>\n",
" <td>22.0</td>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>181</th>\n",
" <td>71.0</td>\n",
" <td>50.0</td>\n",
" <td>40.0</td>\n",
" <td>NaN</td>\n",
" <td>140.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>4.0</td>\n",
" <td>100.0</td>\n",
" <td>147.0</td>\n",
" <td>116.0</td>\n",
" <td>110.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>183</th>\n",
" <td>55.0</td>\n",
" <td>87.0</td>\n",
" <td>93.0</td>\n",
" <td>NaN</td>\n",
" <td>34.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>184</th>\n",
" <td>NaN</td>\n",
" <td>109.0</td>\n",
" <td>124.0</td>\n",
" <td>87.0</td>\n",
" <td>82.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>10.0</td>\n",
" <td>118.0</td>\n",
" <td>139.0</td>\n",
" <td>50.0</td>\n",
" <td>51.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>186</th>\n",
" <td>32.0</td>\n",
" <td>12.0</td>\n",
" <td>71.0</td>\n",
" <td>36.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>187</th>\n",
" <td>94.0</td>\n",
" <td>NaN</td>\n",
" <td>138.0</td>\n",
" <td>13.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>188</th>\n",
" <td>65.0</td>\n",
" <td>101.0</td>\n",
" <td>123.0</td>\n",
" <td>128.0</td>\n",
" <td>86.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>189</th>\n",
" <td>43.0</td>\n",
" <td>94.0</td>\n",
" <td>NaN</td>\n",
" <td>29.0</td>\n",
" <td>132.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>190</th>\n",
" <td>68.0</td>\n",
" <td>135.0</td>\n",
" <td>94.0</td>\n",
" <td>28.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>191</th>\n",
" <td>30.0</td>\n",
" <td>60.0</td>\n",
" <td>98.0</td>\n",
" <td>NaN</td>\n",
" <td>15.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>192</th>\n",
" <td>89.0</td>\n",
" <td>16.0</td>\n",
" <td>10.0</td>\n",
" <td>135.0</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>193</th>\n",
" <td>104.0</td>\n",
" <td>139.0</td>\n",
" <td>97.0</td>\n",
" <td>29.0</td>\n",
" <td>17.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>194</th>\n",
" <td>5.0</td>\n",
" <td>29.0</td>\n",
" <td>41.0</td>\n",
" <td>99.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>195</th>\n",
" <td>19.0</td>\n",
" <td>102.0</td>\n",
" <td>135.0</td>\n",
" <td>41.0</td>\n",
" <td>40.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>196</th>\n",
" <td>58.0</td>\n",
" <td>NaN</td>\n",
" <td>70.0</td>\n",
" <td>82.0</td>\n",
" <td>64.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>197</th>\n",
" <td>NaN</td>\n",
" <td>97.0</td>\n",
" <td>129.0</td>\n",
" <td>76.0</td>\n",
" <td>13.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>131.0</td>\n",
" <td>15.0</td>\n",
" <td>NaN</td>\n",
" <td>44.0</td>\n",
" <td>114.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>199</th>\n",
" <td>79.0</td>\n",
" <td>NaN</td>\n",
" <td>95.0</td>\n",
" <td>128.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 122.0 10.0 5.0 28.0 57.0\n",
"101 NaN 129.0 16.0 114.0 26.0\n",
"102 97.0 121.0 122.0 29.0 65.0\n",
"103 141.0 73.0 120.0 147.0 1.0\n",
"104 126.0 NaN 86.0 116.0 17.0\n",
"105 85.0 NaN 42.0 121.0 66.0\n",
"106 142.0 65.0 1.0 124.0 83.0\n",
"107 136.0 141.0 NaN 86.0 113.0\n",
"108 15.0 37.0 124.0 110.0 102.0\n",
"109 63.0 30.0 NaN 69.0 58.0\n",
"110 NaN NaN 113.0 109.0 16.0\n",
"111 5.0 51.0 87.0 58.0 126.0\n",
"112 53.0 97.0 76.0 37.0 45.0\n",
"113 42.0 148.0 NaN 97.0 NaN\n",
"114 70.0 138.0 69.0 68.0 134.0\n",
"115 NaN 136.0 113.0 22.0 94.0\n",
"116 31.0 137.0 6.0 20.0 28.0\n",
"117 148.0 74.0 134.0 4.0 124.0\n",
"118 102.0 81.0 138.0 128.0 32.0\n",
"119 27.0 111.0 13.0 NaN 22.0\n",
"120 28.0 93.0 121.0 NaN 4.0\n",
"121 136.0 NaN 25.0 97.0 19.0\n",
"122 111.0 70.0 12.0 38.0 58.0\n",
"123 NaN 103.0 147.0 86.0 8.0\n",
"124 10.0 10.0 46.0 63.0 149.0\n",
"125 7.0 75.0 97.0 108.0 31.0\n",
"126 88.0 6.0 NaN NaN 55.0\n",
"127 33.0 74.0 106.0 50.0 46.0\n",
"128 74.0 28.0 26.0 100.0 76.0\n",
"129 76.0 18.0 101.0 NaN NaN\n",
".. ... ... ... ... ...\n",
"170 144.0 124.0 77.0 92.0 82.0\n",
"171 36.0 98.0 NaN 43.0 80.0\n",
"172 51.0 NaN 68.0 34.0 74.0\n",
"173 149.0 NaN 18.0 141.0 NaN\n",
"174 8.0 139.0 146.0 112.0 NaN\n",
"175 115.0 NaN 64.0 62.0 9.0\n",
"176 NaN 7.0 140.0 45.0 148.0\n",
"177 NaN 43.0 68.0 109.0 18.0\n",
"178 31.0 100.0 NaN 49.0 123.0\n",
"179 29.0 46.0 69.0 57.0 90.0\n",
"180 146.0 86.0 18.0 22.0 46.0\n",
"181 71.0 50.0 40.0 NaN 140.0\n",
"182 4.0 100.0 147.0 116.0 110.0\n",
"183 55.0 87.0 93.0 NaN 34.0\n",
"184 NaN 109.0 124.0 87.0 82.0\n",
"185 10.0 118.0 139.0 50.0 51.0\n",
"186 32.0 12.0 71.0 36.0 NaN\n",
"187 94.0 NaN 138.0 13.0 149.0\n",
"188 65.0 101.0 123.0 128.0 86.0\n",
"189 43.0 94.0 NaN 29.0 132.0\n",
"190 68.0 135.0 94.0 28.0 125.0\n",
"191 30.0 60.0 98.0 NaN 15.0\n",
"192 89.0 16.0 10.0 135.0 4.0\n",
"193 104.0 139.0 97.0 29.0 17.0\n",
"194 5.0 29.0 41.0 99.0 NaN\n",
"195 19.0 102.0 135.0 41.0 40.0\n",
"196 58.0 NaN 70.0 82.0 64.0\n",
"197 NaN 97.0 129.0 76.0 13.0\n",
"198 131.0 15.0 NaN 44.0 114.0\n",
"199 79.0 NaN 95.0 128.0 NaN\n",
"\n",
"[100 rows x 5 columns]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python True\n",
"En True\n",
"Math True\n",
"Physic True\n",
"Chem True\n",
"dtype: bool"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.isnull().any()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python 14\n",
"En 14\n",
"Math 15\n",
"Physic 11\n",
"Chem 13\n",
"dtype: int64"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"df2 = df.copy()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python 14\n",
"En 14\n",
"Math 15\n",
"Physic 11\n",
"Chem 13\n",
"dtype: int64"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>122.0</td>\n",
" <td>10.0</td>\n",
" <td>5.0</td>\n",
" <td>28.0</td>\n",
" <td>57.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>100.0</td>\n",
" <td>129.0</td>\n",
" <td>16.0</td>\n",
" <td>114.0</td>\n",
" <td>26.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>97.0</td>\n",
" <td>121.0</td>\n",
" <td>122.0</td>\n",
" <td>29.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>141.0</td>\n",
" <td>73.0</td>\n",
" <td>120.0</td>\n",
" <td>147.0</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>126.0</td>\n",
" <td>100.0</td>\n",
" <td>86.0</td>\n",
" <td>116.0</td>\n",
" <td>17.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>85.0</td>\n",
" <td>100.0</td>\n",
" <td>42.0</td>\n",
" <td>121.0</td>\n",
" <td>66.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>142.0</td>\n",
" <td>65.0</td>\n",
" <td>1.0</td>\n",
" <td>124.0</td>\n",
" <td>83.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>136.0</td>\n",
" <td>141.0</td>\n",
" <td>100.0</td>\n",
" <td>86.0</td>\n",
" <td>113.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>15.0</td>\n",
" <td>37.0</td>\n",
" <td>124.0</td>\n",
" <td>110.0</td>\n",
" <td>102.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>63.0</td>\n",
" <td>30.0</td>\n",
" <td>100.0</td>\n",
" <td>69.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>100.0</td>\n",
" <td>100.0</td>\n",
" <td>113.0</td>\n",
" <td>109.0</td>\n",
" <td>16.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>5.0</td>\n",
" <td>51.0</td>\n",
" <td>87.0</td>\n",
" <td>58.0</td>\n",
" <td>126.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>53.0</td>\n",
" <td>97.0</td>\n",
" <td>76.0</td>\n",
" <td>37.0</td>\n",
" <td>45.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>42.0</td>\n",
" <td>148.0</td>\n",
" <td>100.0</td>\n",
" <td>97.0</td>\n",
" <td>100.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>70.0</td>\n",
" <td>138.0</td>\n",
" <td>69.0</td>\n",
" <td>68.0</td>\n",
" <td>134.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>100.0</td>\n",
" <td>136.0</td>\n",
" <td>113.0</td>\n",
" <td>22.0</td>\n",
" <td>94.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>31.0</td>\n",
" <td>137.0</td>\n",
" <td>6.0</td>\n",
" <td>20.0</td>\n",
" <td>28.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>148.0</td>\n",
" <td>74.0</td>\n",
" <td>134.0</td>\n",
" <td>4.0</td>\n",
" <td>124.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>102.0</td>\n",
" <td>81.0</td>\n",
" <td>138.0</td>\n",
" <td>128.0</td>\n",
" <td>32.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>27.0</td>\n",
" <td>111.0</td>\n",
" <td>13.0</td>\n",
" <td>100.0</td>\n",
" <td>22.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>28.0</td>\n",
" <td>93.0</td>\n",
" <td>121.0</td>\n",
" <td>100.0</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>136.0</td>\n",
" <td>100.0</td>\n",
" <td>25.0</td>\n",
" <td>97.0</td>\n",
" <td>19.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>111.0</td>\n",
" <td>70.0</td>\n",
" <td>12.0</td>\n",
" <td>38.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>100.0</td>\n",
" <td>103.0</td>\n",
" <td>147.0</td>\n",
" <td>86.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>10.0</td>\n",
" <td>10.0</td>\n",
" <td>46.0</td>\n",
" <td>63.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>7.0</td>\n",
" <td>75.0</td>\n",
" <td>97.0</td>\n",
" <td>108.0</td>\n",
" <td>31.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>88.0</td>\n",
" <td>6.0</td>\n",
" <td>100.0</td>\n",
" <td>100.0</td>\n",
" <td>55.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>33.0</td>\n",
" <td>74.0</td>\n",
" <td>106.0</td>\n",
" <td>50.0</td>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>128</th>\n",
" <td>74.0</td>\n",
" <td>28.0</td>\n",
" <td>26.0</td>\n",
" <td>100.0</td>\n",
" <td>76.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>129</th>\n",
" <td>76.0</td>\n",
" <td>18.0</td>\n",
" <td>101.0</td>\n",
" <td>100.0</td>\n",
" <td>100.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>170</th>\n",
" <td>144.0</td>\n",
" <td>124.0</td>\n",
" <td>77.0</td>\n",
" <td>92.0</td>\n",
" <td>82.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>171</th>\n",
" <td>36.0</td>\n",
" <td>98.0</td>\n",
" <td>100.0</td>\n",
" <td>43.0</td>\n",
" <td>80.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>172</th>\n",
" <td>51.0</td>\n",
" <td>100.0</td>\n",
" <td>68.0</td>\n",
" <td>34.0</td>\n",
" <td>74.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>173</th>\n",
" <td>149.0</td>\n",
" <td>100.0</td>\n",
" <td>18.0</td>\n",
" <td>141.0</td>\n",
" <td>100.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>174</th>\n",
" <td>8.0</td>\n",
" <td>139.0</td>\n",
" <td>146.0</td>\n",
" <td>112.0</td>\n",
" <td>100.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>175</th>\n",
" <td>115.0</td>\n",
" <td>100.0</td>\n",
" <td>64.0</td>\n",
" <td>62.0</td>\n",
" <td>9.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>176</th>\n",
" <td>100.0</td>\n",
" <td>7.0</td>\n",
" <td>140.0</td>\n",
" <td>45.0</td>\n",
" <td>148.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>177</th>\n",
" <td>100.0</td>\n",
" <td>43.0</td>\n",
" <td>68.0</td>\n",
" <td>109.0</td>\n",
" <td>18.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>178</th>\n",
" <td>31.0</td>\n",
" <td>100.0</td>\n",
" <td>100.0</td>\n",
" <td>49.0</td>\n",
" <td>123.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>179</th>\n",
" <td>29.0</td>\n",
" <td>46.0</td>\n",
" <td>69.0</td>\n",
" <td>57.0</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>180</th>\n",
" <td>146.0</td>\n",
" <td>86.0</td>\n",
" <td>18.0</td>\n",
" <td>22.0</td>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>181</th>\n",
" <td>71.0</td>\n",
" <td>50.0</td>\n",
" <td>40.0</td>\n",
" <td>100.0</td>\n",
" <td>140.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>4.0</td>\n",
" <td>100.0</td>\n",
" <td>147.0</td>\n",
" <td>116.0</td>\n",
" <td>110.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>183</th>\n",
" <td>55.0</td>\n",
" <td>87.0</td>\n",
" <td>93.0</td>\n",
" <td>100.0</td>\n",
" <td>34.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>184</th>\n",
" <td>100.0</td>\n",
" <td>109.0</td>\n",
" <td>124.0</td>\n",
" <td>87.0</td>\n",
" <td>82.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>10.0</td>\n",
" <td>118.0</td>\n",
" <td>139.0</td>\n",
" <td>50.0</td>\n",
" <td>51.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>186</th>\n",
" <td>32.0</td>\n",
" <td>12.0</td>\n",
" <td>71.0</td>\n",
" <td>36.0</td>\n",
" <td>100.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>187</th>\n",
" <td>94.0</td>\n",
" <td>100.0</td>\n",
" <td>138.0</td>\n",
" <td>13.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>188</th>\n",
" <td>65.0</td>\n",
" <td>101.0</td>\n",
" <td>123.0</td>\n",
" <td>128.0</td>\n",
" <td>86.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>189</th>\n",
" <td>43.0</td>\n",
" <td>94.0</td>\n",
" <td>100.0</td>\n",
" <td>29.0</td>\n",
" <td>132.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>190</th>\n",
" <td>68.0</td>\n",
" <td>135.0</td>\n",
" <td>94.0</td>\n",
" <td>28.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>191</th>\n",
" <td>30.0</td>\n",
" <td>60.0</td>\n",
" <td>98.0</td>\n",
" <td>100.0</td>\n",
" <td>15.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>192</th>\n",
" <td>89.0</td>\n",
" <td>16.0</td>\n",
" <td>10.0</td>\n",
" <td>135.0</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>193</th>\n",
" <td>104.0</td>\n",
" <td>139.0</td>\n",
" <td>97.0</td>\n",
" <td>29.0</td>\n",
" <td>17.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>194</th>\n",
" <td>5.0</td>\n",
" <td>29.0</td>\n",
" <td>41.0</td>\n",
" <td>99.0</td>\n",
" <td>100.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>195</th>\n",
" <td>19.0</td>\n",
" <td>102.0</td>\n",
" <td>135.0</td>\n",
" <td>41.0</td>\n",
" <td>40.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>196</th>\n",
" <td>58.0</td>\n",
" <td>100.0</td>\n",
" <td>70.0</td>\n",
" <td>82.0</td>\n",
" <td>64.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>197</th>\n",
" <td>100.0</td>\n",
" <td>97.0</td>\n",
" <td>129.0</td>\n",
" <td>76.0</td>\n",
" <td>13.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>131.0</td>\n",
" <td>15.0</td>\n",
" <td>100.0</td>\n",
" <td>44.0</td>\n",
" <td>114.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>199</th>\n",
" <td>79.0</td>\n",
" <td>100.0</td>\n",
" <td>95.0</td>\n",
" <td>128.0</td>\n",
" <td>100.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 122.0 10.0 5.0 28.0 57.0\n",
"101 100.0 129.0 16.0 114.0 26.0\n",
"102 97.0 121.0 122.0 29.0 65.0\n",
"103 141.0 73.0 120.0 147.0 1.0\n",
"104 126.0 100.0 86.0 116.0 17.0\n",
"105 85.0 100.0 42.0 121.0 66.0\n",
"106 142.0 65.0 1.0 124.0 83.0\n",
"107 136.0 141.0 100.0 86.0 113.0\n",
"108 15.0 37.0 124.0 110.0 102.0\n",
"109 63.0 30.0 100.0 69.0 58.0\n",
"110 100.0 100.0 113.0 109.0 16.0\n",
"111 5.0 51.0 87.0 58.0 126.0\n",
"112 53.0 97.0 76.0 37.0 45.0\n",
"113 42.0 148.0 100.0 97.0 100.0\n",
"114 70.0 138.0 69.0 68.0 134.0\n",
"115 100.0 136.0 113.0 22.0 94.0\n",
"116 31.0 137.0 6.0 20.0 28.0\n",
"117 148.0 74.0 134.0 4.0 124.0\n",
"118 102.0 81.0 138.0 128.0 32.0\n",
"119 27.0 111.0 13.0 100.0 22.0\n",
"120 28.0 93.0 121.0 100.0 4.0\n",
"121 136.0 100.0 25.0 97.0 19.0\n",
"122 111.0 70.0 12.0 38.0 58.0\n",
"123 100.0 103.0 147.0 86.0 8.0\n",
"124 10.0 10.0 46.0 63.0 149.0\n",
"125 7.0 75.0 97.0 108.0 31.0\n",
"126 88.0 6.0 100.0 100.0 55.0\n",
"127 33.0 74.0 106.0 50.0 46.0\n",
"128 74.0 28.0 26.0 100.0 76.0\n",
"129 76.0 18.0 101.0 100.0 100.0\n",
".. ... ... ... ... ...\n",
"170 144.0 124.0 77.0 92.0 82.0\n",
"171 36.0 98.0 100.0 43.0 80.0\n",
"172 51.0 100.0 68.0 34.0 74.0\n",
"173 149.0 100.0 18.0 141.0 100.0\n",
"174 8.0 139.0 146.0 112.0 100.0\n",
"175 115.0 100.0 64.0 62.0 9.0\n",
"176 100.0 7.0 140.0 45.0 148.0\n",
"177 100.0 43.0 68.0 109.0 18.0\n",
"178 31.0 100.0 100.0 49.0 123.0\n",
"179 29.0 46.0 69.0 57.0 90.0\n",
"180 146.0 86.0 18.0 22.0 46.0\n",
"181 71.0 50.0 40.0 100.0 140.0\n",
"182 4.0 100.0 147.0 116.0 110.0\n",
"183 55.0 87.0 93.0 100.0 34.0\n",
"184 100.0 109.0 124.0 87.0 82.0\n",
"185 10.0 118.0 139.0 50.0 51.0\n",
"186 32.0 12.0 71.0 36.0 100.0\n",
"187 94.0 100.0 138.0 13.0 149.0\n",
"188 65.0 101.0 123.0 128.0 86.0\n",
"189 43.0 94.0 100.0 29.0 132.0\n",
"190 68.0 135.0 94.0 28.0 125.0\n",
"191 30.0 60.0 98.0 100.0 15.0\n",
"192 89.0 16.0 10.0 135.0 4.0\n",
"193 104.0 139.0 97.0 29.0 17.0\n",
"194 5.0 29.0 41.0 99.0 100.0\n",
"195 19.0 102.0 135.0 41.0 40.0\n",
"196 58.0 100.0 70.0 82.0 64.0\n",
"197 100.0 97.0 129.0 76.0 13.0\n",
"198 131.0 15.0 100.0 44.0 114.0\n",
"199 79.0 100.0 95.0 128.0 100.0\n",
"\n",
"[100 rows x 5 columns]"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 固定值填充\n",
"df2.fillna(value=100)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Python 71.662791\n",
"En 75.627907\n",
"Math 77.929412\n",
"Physic 73.471910\n",
"Chem 69.080460\n",
"dtype: float64"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2.mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>122</td>\n",
" <td>10</td>\n",
" <td>5</td>\n",
" <td>28</td>\n",
" <td>57</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>71</td>\n",
" <td>129</td>\n",
" <td>16</td>\n",
" <td>114</td>\n",
" <td>26</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>97</td>\n",
" <td>121</td>\n",
" <td>122</td>\n",
" <td>29</td>\n",
" <td>65</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>141</td>\n",
" <td>73</td>\n",
" <td>120</td>\n",
" <td>147</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>126</td>\n",
" <td>75</td>\n",
" <td>86</td>\n",
" <td>116</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>85</td>\n",
" <td>75</td>\n",
" <td>42</td>\n",
" <td>121</td>\n",
" <td>66</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>142</td>\n",
" <td>65</td>\n",
" <td>1</td>\n",
" <td>124</td>\n",
" <td>83</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>136</td>\n",
" <td>141</td>\n",
" <td>77</td>\n",
" <td>86</td>\n",
" <td>113</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>15</td>\n",
" <td>37</td>\n",
" <td>124</td>\n",
" <td>110</td>\n",
" <td>102</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>63</td>\n",
" <td>30</td>\n",
" <td>77</td>\n",
" <td>69</td>\n",
" <td>58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>71</td>\n",
" <td>75</td>\n",
" <td>113</td>\n",
" <td>109</td>\n",
" <td>16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>5</td>\n",
" <td>51</td>\n",
" <td>87</td>\n",
" <td>58</td>\n",
" <td>126</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>53</td>\n",
" <td>97</td>\n",
" <td>76</td>\n",
" <td>37</td>\n",
" <td>45</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>42</td>\n",
" <td>148</td>\n",
" <td>77</td>\n",
" <td>97</td>\n",
" <td>69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>70</td>\n",
" <td>138</td>\n",
" <td>69</td>\n",
" <td>68</td>\n",
" <td>134</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>71</td>\n",
" <td>136</td>\n",
" <td>113</td>\n",
" <td>22</td>\n",
" <td>94</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>31</td>\n",
" <td>137</td>\n",
" <td>6</td>\n",
" <td>20</td>\n",
" <td>28</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>148</td>\n",
" <td>74</td>\n",
" <td>134</td>\n",
" <td>4</td>\n",
" <td>124</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>102</td>\n",
" <td>81</td>\n",
" <td>138</td>\n",
" <td>128</td>\n",
" <td>32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>27</td>\n",
" <td>111</td>\n",
" <td>13</td>\n",
" <td>73</td>\n",
" <td>22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>28</td>\n",
" <td>93</td>\n",
" <td>121</td>\n",
" <td>73</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>136</td>\n",
" <td>75</td>\n",
" <td>25</td>\n",
" <td>97</td>\n",
" <td>19</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>111</td>\n",
" <td>70</td>\n",
" <td>12</td>\n",
" <td>38</td>\n",
" <td>58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>71</td>\n",
" <td>103</td>\n",
" <td>147</td>\n",
" <td>86</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>10</td>\n",
" <td>10</td>\n",
" <td>46</td>\n",
" <td>63</td>\n",
" <td>149</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>7</td>\n",
" <td>75</td>\n",
" <td>97</td>\n",
" <td>108</td>\n",
" <td>31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>88</td>\n",
" <td>6</td>\n",
" <td>77</td>\n",
" <td>73</td>\n",
" <td>55</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>33</td>\n",
" <td>74</td>\n",
" <td>106</td>\n",
" <td>50</td>\n",
" <td>46</td>\n",
" </tr>\n",
" <tr>\n",
" <th>128</th>\n",
" <td>74</td>\n",
" <td>28</td>\n",
" <td>26</td>\n",
" <td>100</td>\n",
" <td>76</td>\n",
" </tr>\n",
" <tr>\n",
" <th>129</th>\n",
" <td>76</td>\n",
" <td>18</td>\n",
" <td>101</td>\n",
" <td>73</td>\n",
" <td>69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>170</th>\n",
" <td>144</td>\n",
" <td>124</td>\n",
" <td>77</td>\n",
" <td>92</td>\n",
" <td>82</td>\n",
" </tr>\n",
" <tr>\n",
" <th>171</th>\n",
" <td>36</td>\n",
" <td>98</td>\n",
" <td>77</td>\n",
" <td>43</td>\n",
" <td>80</td>\n",
" </tr>\n",
" <tr>\n",
" <th>172</th>\n",
" <td>51</td>\n",
" <td>75</td>\n",
" <td>68</td>\n",
" <td>34</td>\n",
" <td>74</td>\n",
" </tr>\n",
" <tr>\n",
" <th>173</th>\n",
" <td>149</td>\n",
" <td>75</td>\n",
" <td>18</td>\n",
" <td>141</td>\n",
" <td>69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>174</th>\n",
" <td>8</td>\n",
" <td>139</td>\n",
" <td>146</td>\n",
" <td>112</td>\n",
" <td>69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>175</th>\n",
" <td>115</td>\n",
" <td>75</td>\n",
" <td>64</td>\n",
" <td>62</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>176</th>\n",
" <td>71</td>\n",
" <td>7</td>\n",
" <td>140</td>\n",
" <td>45</td>\n",
" <td>148</td>\n",
" </tr>\n",
" <tr>\n",
" <th>177</th>\n",
" <td>71</td>\n",
" <td>43</td>\n",
" <td>68</td>\n",
" <td>109</td>\n",
" <td>18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>178</th>\n",
" <td>31</td>\n",
" <td>100</td>\n",
" <td>77</td>\n",
" <td>49</td>\n",
" <td>123</td>\n",
" </tr>\n",
" <tr>\n",
" <th>179</th>\n",
" <td>29</td>\n",
" <td>46</td>\n",
" <td>69</td>\n",
" <td>57</td>\n",
" <td>90</td>\n",
" </tr>\n",
" <tr>\n",
" <th>180</th>\n",
" <td>146</td>\n",
" <td>86</td>\n",
" <td>18</td>\n",
" <td>22</td>\n",
" <td>46</td>\n",
" </tr>\n",
" <tr>\n",
" <th>181</th>\n",
" <td>71</td>\n",
" <td>50</td>\n",
" <td>40</td>\n",
" <td>73</td>\n",
" <td>140</td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>4</td>\n",
" <td>100</td>\n",
" <td>147</td>\n",
" <td>116</td>\n",
" <td>110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>183</th>\n",
" <td>55</td>\n",
" <td>87</td>\n",
" <td>93</td>\n",
" <td>73</td>\n",
" <td>34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>184</th>\n",
" <td>71</td>\n",
" <td>109</td>\n",
" <td>124</td>\n",
" <td>87</td>\n",
" <td>82</td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>10</td>\n",
" <td>118</td>\n",
" <td>139</td>\n",
" <td>50</td>\n",
" <td>51</td>\n",
" </tr>\n",
" <tr>\n",
" <th>186</th>\n",
" <td>32</td>\n",
" <td>12</td>\n",
" <td>71</td>\n",
" <td>36</td>\n",
" <td>69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>187</th>\n",
" <td>94</td>\n",
" <td>75</td>\n",
" <td>138</td>\n",
" <td>13</td>\n",
" <td>149</td>\n",
" </tr>\n",
" <tr>\n",
" <th>188</th>\n",
" <td>65</td>\n",
" <td>101</td>\n",
" <td>123</td>\n",
" <td>128</td>\n",
" <td>86</td>\n",
" </tr>\n",
" <tr>\n",
" <th>189</th>\n",
" <td>43</td>\n",
" <td>94</td>\n",
" <td>77</td>\n",
" <td>29</td>\n",
" <td>132</td>\n",
" </tr>\n",
" <tr>\n",
" <th>190</th>\n",
" <td>68</td>\n",
" <td>135</td>\n",
" <td>94</td>\n",
" <td>28</td>\n",
" <td>125</td>\n",
" </tr>\n",
" <tr>\n",
" <th>191</th>\n",
" <td>30</td>\n",
" <td>60</td>\n",
" <td>98</td>\n",
" <td>73</td>\n",
" <td>15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>192</th>\n",
" <td>89</td>\n",
" <td>16</td>\n",
" <td>10</td>\n",
" <td>135</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>193</th>\n",
" <td>104</td>\n",
" <td>139</td>\n",
" <td>97</td>\n",
" <td>29</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>194</th>\n",
" <td>5</td>\n",
" <td>29</td>\n",
" <td>41</td>\n",
" <td>99</td>\n",
" <td>69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>195</th>\n",
" <td>19</td>\n",
" <td>102</td>\n",
" <td>135</td>\n",
" <td>41</td>\n",
" <td>40</td>\n",
" </tr>\n",
" <tr>\n",
" <th>196</th>\n",
" <td>58</td>\n",
" <td>75</td>\n",
" <td>70</td>\n",
" <td>82</td>\n",
" <td>64</td>\n",
" </tr>\n",
" <tr>\n",
" <th>197</th>\n",
" <td>71</td>\n",
" <td>97</td>\n",
" <td>129</td>\n",
" <td>76</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>131</td>\n",
" <td>15</td>\n",
" <td>77</td>\n",
" <td>44</td>\n",
" <td>114</td>\n",
" </tr>\n",
" <tr>\n",
" <th>199</th>\n",
" <td>79</td>\n",
" <td>75</td>\n",
" <td>95</td>\n",
" <td>128</td>\n",
" <td>69</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 122 10 5 28 57\n",
"101 71 129 16 114 26\n",
"102 97 121 122 29 65\n",
"103 141 73 120 147 1\n",
"104 126 75 86 116 17\n",
"105 85 75 42 121 66\n",
"106 142 65 1 124 83\n",
"107 136 141 77 86 113\n",
"108 15 37 124 110 102\n",
"109 63 30 77 69 58\n",
"110 71 75 113 109 16\n",
"111 5 51 87 58 126\n",
"112 53 97 76 37 45\n",
"113 42 148 77 97 69\n",
"114 70 138 69 68 134\n",
"115 71 136 113 22 94\n",
"116 31 137 6 20 28\n",
"117 148 74 134 4 124\n",
"118 102 81 138 128 32\n",
"119 27 111 13 73 22\n",
"120 28 93 121 73 4\n",
"121 136 75 25 97 19\n",
"122 111 70 12 38 58\n",
"123 71 103 147 86 8\n",
"124 10 10 46 63 149\n",
"125 7 75 97 108 31\n",
"126 88 6 77 73 55\n",
"127 33 74 106 50 46\n",
"128 74 28 26 100 76\n",
"129 76 18 101 73 69\n",
".. ... ... ... ... ...\n",
"170 144 124 77 92 82\n",
"171 36 98 77 43 80\n",
"172 51 75 68 34 74\n",
"173 149 75 18 141 69\n",
"174 8 139 146 112 69\n",
"175 115 75 64 62 9\n",
"176 71 7 140 45 148\n",
"177 71 43 68 109 18\n",
"178 31 100 77 49 123\n",
"179 29 46 69 57 90\n",
"180 146 86 18 22 46\n",
"181 71 50 40 73 140\n",
"182 4 100 147 116 110\n",
"183 55 87 93 73 34\n",
"184 71 109 124 87 82\n",
"185 10 118 139 50 51\n",
"186 32 12 71 36 69\n",
"187 94 75 138 13 149\n",
"188 65 101 123 128 86\n",
"189 43 94 77 29 132\n",
"190 68 135 94 28 125\n",
"191 30 60 98 73 15\n",
"192 89 16 10 135 4\n",
"193 104 139 97 29 17\n",
"194 5 29 41 99 69\n",
"195 19 102 135 41 40\n",
"196 58 75 70 82 64\n",
"197 71 97 129 76 13\n",
"198 131 15 77 44 114\n",
"199 79 75 95 128 69\n",
"\n",
"[100 rows x 5 columns]"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 均值\n",
"df3 = df2.fillna(value=df2.mean())\n",
"df3.astype(np.int16)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 6, 18, 1, 17, 19, 5, 17, 16, 13, 3])"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nd = np.random.randint(0,20,size = 10)\n",
"nd"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1, 3, 5, 6, 13, 16, 17, 17, 18, 19])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nd.sort()\n",
"nd"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14.5"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(13 + 16)/2"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14.5"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.median(nd)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>122.0</td>\n",
" <td>10.0</td>\n",
" <td>5.0</td>\n",
" <td>28.0</td>\n",
" <td>57.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>68.0</td>\n",
" <td>129.0</td>\n",
" <td>16.0</td>\n",
" <td>114.0</td>\n",
" <td>26.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>97.0</td>\n",
" <td>121.0</td>\n",
" <td>122.0</td>\n",
" <td>29.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>141.0</td>\n",
" <td>73.0</td>\n",
" <td>120.0</td>\n",
" <td>147.0</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>126.0</td>\n",
" <td>82.5</td>\n",
" <td>86.0</td>\n",
" <td>116.0</td>\n",
" <td>17.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>85.0</td>\n",
" <td>82.5</td>\n",
" <td>42.0</td>\n",
" <td>121.0</td>\n",
" <td>66.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>142.0</td>\n",
" <td>65.0</td>\n",
" <td>1.0</td>\n",
" <td>124.0</td>\n",
" <td>83.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>136.0</td>\n",
" <td>141.0</td>\n",
" <td>86.0</td>\n",
" <td>86.0</td>\n",
" <td>113.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>15.0</td>\n",
" <td>37.0</td>\n",
" <td>124.0</td>\n",
" <td>110.0</td>\n",
" <td>102.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>63.0</td>\n",
" <td>30.0</td>\n",
" <td>86.0</td>\n",
" <td>69.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>68.0</td>\n",
" <td>82.5</td>\n",
" <td>113.0</td>\n",
" <td>109.0</td>\n",
" <td>16.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>5.0</td>\n",
" <td>51.0</td>\n",
" <td>87.0</td>\n",
" <td>58.0</td>\n",
" <td>126.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>53.0</td>\n",
" <td>97.0</td>\n",
" <td>76.0</td>\n",
" <td>37.0</td>\n",
" <td>45.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>42.0</td>\n",
" <td>148.0</td>\n",
" <td>86.0</td>\n",
" <td>97.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>70.0</td>\n",
" <td>138.0</td>\n",
" <td>69.0</td>\n",
" <td>68.0</td>\n",
" <td>134.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>68.0</td>\n",
" <td>136.0</td>\n",
" <td>113.0</td>\n",
" <td>22.0</td>\n",
" <td>94.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>31.0</td>\n",
" <td>137.0</td>\n",
" <td>6.0</td>\n",
" <td>20.0</td>\n",
" <td>28.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>148.0</td>\n",
" <td>74.0</td>\n",
" <td>134.0</td>\n",
" <td>4.0</td>\n",
" <td>124.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>102.0</td>\n",
" <td>81.0</td>\n",
" <td>138.0</td>\n",
" <td>128.0</td>\n",
" <td>32.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>27.0</td>\n",
" <td>111.0</td>\n",
" <td>13.0</td>\n",
" <td>69.0</td>\n",
" <td>22.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>28.0</td>\n",
" <td>93.0</td>\n",
" <td>121.0</td>\n",
" <td>69.0</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>136.0</td>\n",
" <td>82.5</td>\n",
" <td>25.0</td>\n",
" <td>97.0</td>\n",
" <td>19.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>111.0</td>\n",
" <td>70.0</td>\n",
" <td>12.0</td>\n",
" <td>38.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>68.0</td>\n",
" <td>103.0</td>\n",
" <td>147.0</td>\n",
" <td>86.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>10.0</td>\n",
" <td>10.0</td>\n",
" <td>46.0</td>\n",
" <td>63.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>7.0</td>\n",
" <td>75.0</td>\n",
" <td>97.0</td>\n",
" <td>108.0</td>\n",
" <td>31.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>88.0</td>\n",
" <td>6.0</td>\n",
" <td>86.0</td>\n",
" <td>69.0</td>\n",
" <td>55.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>33.0</td>\n",
" <td>74.0</td>\n",
" <td>106.0</td>\n",
" <td>50.0</td>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>128</th>\n",
" <td>74.0</td>\n",
" <td>28.0</td>\n",
" <td>26.0</td>\n",
" <td>100.0</td>\n",
" <td>76.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>129</th>\n",
" <td>76.0</td>\n",
" <td>18.0</td>\n",
" <td>101.0</td>\n",
" <td>69.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>170</th>\n",
" <td>144.0</td>\n",
" <td>124.0</td>\n",
" <td>77.0</td>\n",
" <td>92.0</td>\n",
" <td>82.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>171</th>\n",
" <td>36.0</td>\n",
" <td>98.0</td>\n",
" <td>86.0</td>\n",
" <td>43.0</td>\n",
" <td>80.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>172</th>\n",
" <td>51.0</td>\n",
" <td>82.5</td>\n",
" <td>68.0</td>\n",
" <td>34.0</td>\n",
" <td>74.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>173</th>\n",
" <td>149.0</td>\n",
" <td>82.5</td>\n",
" <td>18.0</td>\n",
" <td>141.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>174</th>\n",
" <td>8.0</td>\n",
" <td>139.0</td>\n",
" <td>146.0</td>\n",
" <td>112.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>175</th>\n",
" <td>115.0</td>\n",
" <td>82.5</td>\n",
" <td>64.0</td>\n",
" <td>62.0</td>\n",
" <td>9.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>176</th>\n",
" <td>68.0</td>\n",
" <td>7.0</td>\n",
" <td>140.0</td>\n",
" <td>45.0</td>\n",
" <td>148.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>177</th>\n",
" <td>68.0</td>\n",
" <td>43.0</td>\n",
" <td>68.0</td>\n",
" <td>109.0</td>\n",
" <td>18.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>178</th>\n",
" <td>31.0</td>\n",
" <td>100.0</td>\n",
" <td>86.0</td>\n",
" <td>49.0</td>\n",
" <td>123.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>179</th>\n",
" <td>29.0</td>\n",
" <td>46.0</td>\n",
" <td>69.0</td>\n",
" <td>57.0</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>180</th>\n",
" <td>146.0</td>\n",
" <td>86.0</td>\n",
" <td>18.0</td>\n",
" <td>22.0</td>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>181</th>\n",
" <td>71.0</td>\n",
" <td>50.0</td>\n",
" <td>40.0</td>\n",
" <td>69.0</td>\n",
" <td>140.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>4.0</td>\n",
" <td>100.0</td>\n",
" <td>147.0</td>\n",
" <td>116.0</td>\n",
" <td>110.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>183</th>\n",
" <td>55.0</td>\n",
" <td>87.0</td>\n",
" <td>93.0</td>\n",
" <td>69.0</td>\n",
" <td>34.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>184</th>\n",
" <td>68.0</td>\n",
" <td>109.0</td>\n",
" <td>124.0</td>\n",
" <td>87.0</td>\n",
" <td>82.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>10.0</td>\n",
" <td>118.0</td>\n",
" <td>139.0</td>\n",
" <td>50.0</td>\n",
" <td>51.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>186</th>\n",
" <td>32.0</td>\n",
" <td>12.0</td>\n",
" <td>71.0</td>\n",
" <td>36.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>187</th>\n",
" <td>94.0</td>\n",
" <td>82.5</td>\n",
" <td>138.0</td>\n",
" <td>13.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>188</th>\n",
" <td>65.0</td>\n",
" <td>101.0</td>\n",
" <td>123.0</td>\n",
" <td>128.0</td>\n",
" <td>86.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>189</th>\n",
" <td>43.0</td>\n",
" <td>94.0</td>\n",
" <td>86.0</td>\n",
" <td>29.0</td>\n",
" <td>132.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>190</th>\n",
" <td>68.0</td>\n",
" <td>135.0</td>\n",
" <td>94.0</td>\n",
" <td>28.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>191</th>\n",
" <td>30.0</td>\n",
" <td>60.0</td>\n",
" <td>98.0</td>\n",
" <td>69.0</td>\n",
" <td>15.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>192</th>\n",
" <td>89.0</td>\n",
" <td>16.0</td>\n",
" <td>10.0</td>\n",
" <td>135.0</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>193</th>\n",
" <td>104.0</td>\n",
" <td>139.0</td>\n",
" <td>97.0</td>\n",
" <td>29.0</td>\n",
" <td>17.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>194</th>\n",
" <td>5.0</td>\n",
" <td>29.0</td>\n",
" <td>41.0</td>\n",
" <td>99.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>195</th>\n",
" <td>19.0</td>\n",
" <td>102.0</td>\n",
" <td>135.0</td>\n",
" <td>41.0</td>\n",
" <td>40.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>196</th>\n",
" <td>58.0</td>\n",
" <td>82.5</td>\n",
" <td>70.0</td>\n",
" <td>82.0</td>\n",
" <td>64.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>197</th>\n",
" <td>68.0</td>\n",
" <td>97.0</td>\n",
" <td>129.0</td>\n",
" <td>76.0</td>\n",
" <td>13.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>131.0</td>\n",
" <td>15.0</td>\n",
" <td>86.0</td>\n",
" <td>44.0</td>\n",
" <td>114.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>199</th>\n",
" <td>79.0</td>\n",
" <td>82.5</td>\n",
" <td>95.0</td>\n",
" <td>128.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 122.0 10.0 5.0 28.0 57.0\n",
"101 68.0 129.0 16.0 114.0 26.0\n",
"102 97.0 121.0 122.0 29.0 65.0\n",
"103 141.0 73.0 120.0 147.0 1.0\n",
"104 126.0 82.5 86.0 116.0 17.0\n",
"105 85.0 82.5 42.0 121.0 66.0\n",
"106 142.0 65.0 1.0 124.0 83.0\n",
"107 136.0 141.0 86.0 86.0 113.0\n",
"108 15.0 37.0 124.0 110.0 102.0\n",
"109 63.0 30.0 86.0 69.0 58.0\n",
"110 68.0 82.5 113.0 109.0 16.0\n",
"111 5.0 51.0 87.0 58.0 126.0\n",
"112 53.0 97.0 76.0 37.0 45.0\n",
"113 42.0 148.0 86.0 97.0 65.0\n",
"114 70.0 138.0 69.0 68.0 134.0\n",
"115 68.0 136.0 113.0 22.0 94.0\n",
"116 31.0 137.0 6.0 20.0 28.0\n",
"117 148.0 74.0 134.0 4.0 124.0\n",
"118 102.0 81.0 138.0 128.0 32.0\n",
"119 27.0 111.0 13.0 69.0 22.0\n",
"120 28.0 93.0 121.0 69.0 4.0\n",
"121 136.0 82.5 25.0 97.0 19.0\n",
"122 111.0 70.0 12.0 38.0 58.0\n",
"123 68.0 103.0 147.0 86.0 8.0\n",
"124 10.0 10.0 46.0 63.0 149.0\n",
"125 7.0 75.0 97.0 108.0 31.0\n",
"126 88.0 6.0 86.0 69.0 55.0\n",
"127 33.0 74.0 106.0 50.0 46.0\n",
"128 74.0 28.0 26.0 100.0 76.0\n",
"129 76.0 18.0 101.0 69.0 65.0\n",
".. ... ... ... ... ...\n",
"170 144.0 124.0 77.0 92.0 82.0\n",
"171 36.0 98.0 86.0 43.0 80.0\n",
"172 51.0 82.5 68.0 34.0 74.0\n",
"173 149.0 82.5 18.0 141.0 65.0\n",
"174 8.0 139.0 146.0 112.0 65.0\n",
"175 115.0 82.5 64.0 62.0 9.0\n",
"176 68.0 7.0 140.0 45.0 148.0\n",
"177 68.0 43.0 68.0 109.0 18.0\n",
"178 31.0 100.0 86.0 49.0 123.0\n",
"179 29.0 46.0 69.0 57.0 90.0\n",
"180 146.0 86.0 18.0 22.0 46.0\n",
"181 71.0 50.0 40.0 69.0 140.0\n",
"182 4.0 100.0 147.0 116.0 110.0\n",
"183 55.0 87.0 93.0 69.0 34.0\n",
"184 68.0 109.0 124.0 87.0 82.0\n",
"185 10.0 118.0 139.0 50.0 51.0\n",
"186 32.0 12.0 71.0 36.0 65.0\n",
"187 94.0 82.5 138.0 13.0 149.0\n",
"188 65.0 101.0 123.0 128.0 86.0\n",
"189 43.0 94.0 86.0 29.0 132.0\n",
"190 68.0 135.0 94.0 28.0 125.0\n",
"191 30.0 60.0 98.0 69.0 15.0\n",
"192 89.0 16.0 10.0 135.0 4.0\n",
"193 104.0 139.0 97.0 29.0 17.0\n",
"194 5.0 29.0 41.0 99.0 65.0\n",
"195 19.0 102.0 135.0 41.0 40.0\n",
"196 58.0 82.5 70.0 82.0 64.0\n",
"197 68.0 97.0 129.0 76.0 13.0\n",
"198 131.0 15.0 86.0 44.0 114.0\n",
"199 79.0 82.5 95.0 128.0 65.0\n",
"\n",
"[100 rows x 5 columns]"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 中位数填充\n",
"df2.median()\n",
"df4 = df2.fillna(df2.median())\n",
"df4"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>122.0</td>\n",
" <td>10.0</td>\n",
" <td>5.0</td>\n",
" <td>28.0</td>\n",
" <td>57.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>NaN</td>\n",
" <td>129.0</td>\n",
" <td>16.0</td>\n",
" <td>114.0</td>\n",
" <td>26.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>97.0</td>\n",
" <td>121.0</td>\n",
" <td>122.0</td>\n",
" <td>29.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>141.0</td>\n",
" <td>73.0</td>\n",
" <td>120.0</td>\n",
" <td>147.0</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>126.0</td>\n",
" <td>NaN</td>\n",
" <td>86.0</td>\n",
" <td>116.0</td>\n",
" <td>17.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>85.0</td>\n",
" <td>NaN</td>\n",
" <td>42.0</td>\n",
" <td>121.0</td>\n",
" <td>66.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>142.0</td>\n",
" <td>65.0</td>\n",
" <td>1.0</td>\n",
" <td>124.0</td>\n",
" <td>83.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>136.0</td>\n",
" <td>141.0</td>\n",
" <td>NaN</td>\n",
" <td>86.0</td>\n",
" <td>113.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>15.0</td>\n",
" <td>37.0</td>\n",
" <td>124.0</td>\n",
" <td>110.0</td>\n",
" <td>102.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>63.0</td>\n",
" <td>30.0</td>\n",
" <td>NaN</td>\n",
" <td>69.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>113.0</td>\n",
" <td>109.0</td>\n",
" <td>16.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>5.0</td>\n",
" <td>51.0</td>\n",
" <td>87.0</td>\n",
" <td>58.0</td>\n",
" <td>126.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>53.0</td>\n",
" <td>97.0</td>\n",
" <td>76.0</td>\n",
" <td>37.0</td>\n",
" <td>45.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>42.0</td>\n",
" <td>148.0</td>\n",
" <td>NaN</td>\n",
" <td>97.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>70.0</td>\n",
" <td>138.0</td>\n",
" <td>69.0</td>\n",
" <td>68.0</td>\n",
" <td>134.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>NaN</td>\n",
" <td>136.0</td>\n",
" <td>113.0</td>\n",
" <td>22.0</td>\n",
" <td>94.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>31.0</td>\n",
" <td>137.0</td>\n",
" <td>6.0</td>\n",
" <td>20.0</td>\n",
" <td>28.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>148.0</td>\n",
" <td>74.0</td>\n",
" <td>134.0</td>\n",
" <td>4.0</td>\n",
" <td>124.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>102.0</td>\n",
" <td>81.0</td>\n",
" <td>138.0</td>\n",
" <td>128.0</td>\n",
" <td>32.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>27.0</td>\n",
" <td>111.0</td>\n",
" <td>13.0</td>\n",
" <td>NaN</td>\n",
" <td>22.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>28.0</td>\n",
" <td>93.0</td>\n",
" <td>121.0</td>\n",
" <td>NaN</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>136.0</td>\n",
" <td>NaN</td>\n",
" <td>25.0</td>\n",
" <td>97.0</td>\n",
" <td>19.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>111.0</td>\n",
" <td>70.0</td>\n",
" <td>12.0</td>\n",
" <td>38.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>NaN</td>\n",
" <td>103.0</td>\n",
" <td>147.0</td>\n",
" <td>86.0</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>10.0</td>\n",
" <td>10.0</td>\n",
" <td>46.0</td>\n",
" <td>63.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>7.0</td>\n",
" <td>75.0</td>\n",
" <td>97.0</td>\n",
" <td>108.0</td>\n",
" <td>31.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>88.0</td>\n",
" <td>6.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>55.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>33.0</td>\n",
" <td>74.0</td>\n",
" <td>106.0</td>\n",
" <td>50.0</td>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>128</th>\n",
" <td>74.0</td>\n",
" <td>28.0</td>\n",
" <td>26.0</td>\n",
" <td>100.0</td>\n",
" <td>76.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>129</th>\n",
" <td>76.0</td>\n",
" <td>18.0</td>\n",
" <td>101.0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>170</th>\n",
" <td>144.0</td>\n",
" <td>124.0</td>\n",
" <td>77.0</td>\n",
" <td>92.0</td>\n",
" <td>82.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>171</th>\n",
" <td>36.0</td>\n",
" <td>98.0</td>\n",
" <td>NaN</td>\n",
" <td>43.0</td>\n",
" <td>80.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>172</th>\n",
" <td>51.0</td>\n",
" <td>NaN</td>\n",
" <td>68.0</td>\n",
" <td>34.0</td>\n",
" <td>74.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>173</th>\n",
" <td>149.0</td>\n",
" <td>NaN</td>\n",
" <td>18.0</td>\n",
" <td>141.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>174</th>\n",
" <td>8.0</td>\n",
" <td>139.0</td>\n",
" <td>146.0</td>\n",
" <td>112.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>175</th>\n",
" <td>115.0</td>\n",
" <td>NaN</td>\n",
" <td>64.0</td>\n",
" <td>62.0</td>\n",
" <td>9.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>176</th>\n",
" <td>NaN</td>\n",
" <td>7.0</td>\n",
" <td>140.0</td>\n",
" <td>45.0</td>\n",
" <td>148.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>177</th>\n",
" <td>NaN</td>\n",
" <td>43.0</td>\n",
" <td>68.0</td>\n",
" <td>109.0</td>\n",
" <td>18.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>178</th>\n",
" <td>31.0</td>\n",
" <td>100.0</td>\n",
" <td>NaN</td>\n",
" <td>49.0</td>\n",
" <td>123.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>179</th>\n",
" <td>29.0</td>\n",
" <td>46.0</td>\n",
" <td>69.0</td>\n",
" <td>57.0</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>180</th>\n",
" <td>146.0</td>\n",
" <td>86.0</td>\n",
" <td>18.0</td>\n",
" <td>22.0</td>\n",
" <td>46.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>181</th>\n",
" <td>71.0</td>\n",
" <td>50.0</td>\n",
" <td>40.0</td>\n",
" <td>NaN</td>\n",
" <td>140.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>182</th>\n",
" <td>4.0</td>\n",
" <td>100.0</td>\n",
" <td>147.0</td>\n",
" <td>116.0</td>\n",
" <td>110.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>183</th>\n",
" <td>55.0</td>\n",
" <td>87.0</td>\n",
" <td>93.0</td>\n",
" <td>NaN</td>\n",
" <td>34.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>184</th>\n",
" <td>NaN</td>\n",
" <td>109.0</td>\n",
" <td>124.0</td>\n",
" <td>87.0</td>\n",
" <td>82.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>185</th>\n",
" <td>10.0</td>\n",
" <td>118.0</td>\n",
" <td>139.0</td>\n",
" <td>50.0</td>\n",
" <td>51.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>186</th>\n",
" <td>32.0</td>\n",
" <td>12.0</td>\n",
" <td>71.0</td>\n",
" <td>36.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>187</th>\n",
" <td>94.0</td>\n",
" <td>NaN</td>\n",
" <td>138.0</td>\n",
" <td>13.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>188</th>\n",
" <td>65.0</td>\n",
" <td>101.0</td>\n",
" <td>123.0</td>\n",
" <td>128.0</td>\n",
" <td>86.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>189</th>\n",
" <td>43.0</td>\n",
" <td>94.0</td>\n",
" <td>NaN</td>\n",
" <td>29.0</td>\n",
" <td>132.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>190</th>\n",
" <td>68.0</td>\n",
" <td>135.0</td>\n",
" <td>94.0</td>\n",
" <td>28.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>191</th>\n",
" <td>30.0</td>\n",
" <td>60.0</td>\n",
" <td>98.0</td>\n",
" <td>NaN</td>\n",
" <td>15.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>192</th>\n",
" <td>89.0</td>\n",
" <td>16.0</td>\n",
" <td>10.0</td>\n",
" <td>135.0</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>193</th>\n",
" <td>104.0</td>\n",
" <td>139.0</td>\n",
" <td>97.0</td>\n",
" <td>29.0</td>\n",
" <td>17.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>194</th>\n",
" <td>5.0</td>\n",
" <td>29.0</td>\n",
" <td>41.0</td>\n",
" <td>99.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>195</th>\n",
" <td>19.0</td>\n",
" <td>102.0</td>\n",
" <td>135.0</td>\n",
" <td>41.0</td>\n",
" <td>40.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>196</th>\n",
" <td>58.0</td>\n",
" <td>NaN</td>\n",
" <td>70.0</td>\n",
" <td>82.0</td>\n",
" <td>64.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>197</th>\n",
" <td>NaN</td>\n",
" <td>97.0</td>\n",
" <td>129.0</td>\n",
" <td>76.0</td>\n",
" <td>13.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>198</th>\n",
" <td>131.0</td>\n",
" <td>15.0</td>\n",
" <td>NaN</td>\n",
" <td>44.0</td>\n",
" <td>114.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>199</th>\n",
" <td>79.0</td>\n",
" <td>NaN</td>\n",
" <td>95.0</td>\n",
" <td>128.0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 122.0 10.0 5.0 28.0 57.0\n",
"101 NaN 129.0 16.0 114.0 26.0\n",
"102 97.0 121.0 122.0 29.0 65.0\n",
"103 141.0 73.0 120.0 147.0 1.0\n",
"104 126.0 NaN 86.0 116.0 17.0\n",
"105 85.0 NaN 42.0 121.0 66.0\n",
"106 142.0 65.0 1.0 124.0 83.0\n",
"107 136.0 141.0 NaN 86.0 113.0\n",
"108 15.0 37.0 124.0 110.0 102.0\n",
"109 63.0 30.0 NaN 69.0 58.0\n",
"110 NaN NaN 113.0 109.0 16.0\n",
"111 5.0 51.0 87.0 58.0 126.0\n",
"112 53.0 97.0 76.0 37.0 45.0\n",
"113 42.0 148.0 NaN 97.0 NaN\n",
"114 70.0 138.0 69.0 68.0 134.0\n",
"115 NaN 136.0 113.0 22.0 94.0\n",
"116 31.0 137.0 6.0 20.0 28.0\n",
"117 148.0 74.0 134.0 4.0 124.0\n",
"118 102.0 81.0 138.0 128.0 32.0\n",
"119 27.0 111.0 13.0 NaN 22.0\n",
"120 28.0 93.0 121.0 NaN 4.0\n",
"121 136.0 NaN 25.0 97.0 19.0\n",
"122 111.0 70.0 12.0 38.0 58.0\n",
"123 NaN 103.0 147.0 86.0 8.0\n",
"124 10.0 10.0 46.0 63.0 149.0\n",
"125 7.0 75.0 97.0 108.0 31.0\n",
"126 88.0 6.0 NaN NaN 55.0\n",
"127 33.0 74.0 106.0 50.0 46.0\n",
"128 74.0 28.0 26.0 100.0 76.0\n",
"129 76.0 18.0 101.0 NaN NaN\n",
".. ... ... ... ... ...\n",
"170 144.0 124.0 77.0 92.0 82.0\n",
"171 36.0 98.0 NaN 43.0 80.0\n",
"172 51.0 NaN 68.0 34.0 74.0\n",
"173 149.0 NaN 18.0 141.0 NaN\n",
"174 8.0 139.0 146.0 112.0 NaN\n",
"175 115.0 NaN 64.0 62.0 9.0\n",
"176 NaN 7.0 140.0 45.0 148.0\n",
"177 NaN 43.0 68.0 109.0 18.0\n",
"178 31.0 100.0 NaN 49.0 123.0\n",
"179 29.0 46.0 69.0 57.0 90.0\n",
"180 146.0 86.0 18.0 22.0 46.0\n",
"181 71.0 50.0 40.0 NaN 140.0\n",
"182 4.0 100.0 147.0 116.0 110.0\n",
"183 55.0 87.0 93.0 NaN 34.0\n",
"184 NaN 109.0 124.0 87.0 82.0\n",
"185 10.0 118.0 139.0 50.0 51.0\n",
"186 32.0 12.0 71.0 36.0 NaN\n",
"187 94.0 NaN 138.0 13.0 149.0\n",
"188 65.0 101.0 123.0 128.0 86.0\n",
"189 43.0 94.0 NaN 29.0 132.0\n",
"190 68.0 135.0 94.0 28.0 125.0\n",
"191 30.0 60.0 98.0 NaN 15.0\n",
"192 89.0 16.0 10.0 135.0 4.0\n",
"193 104.0 139.0 97.0 29.0 17.0\n",
"194 5.0 29.0 41.0 99.0 NaN\n",
"195 19.0 102.0 135.0 41.0 40.0\n",
"196 58.0 NaN 70.0 82.0 64.0\n",
"197 NaN 97.0 129.0 76.0 13.0\n",
"198 131.0 15.0 NaN 44.0 114.0\n",
"199 79.0 NaN 95.0 128.0 NaN\n",
"\n",
"[100 rows x 5 columns]"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 众数填充,数量最多的那个数\n",
"df2"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>82</td>\n",
" <td>89</td>\n",
" <td>99</td>\n",
" <td>101</td>\n",
" <td>125</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>4</td>\n",
" <td>31</td>\n",
" <td>109</td>\n",
" <td>32</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>56</td>\n",
" <td>103</td>\n",
" <td>56</td>\n",
" <td>61</td>\n",
" <td>90</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>47</td>\n",
" <td>100</td>\n",
" <td>147</td>\n",
" <td>138</td>\n",
" <td>99</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>38</td>\n",
" <td>46</td>\n",
" <td>82</td>\n",
" <td>75</td>\n",
" <td>44</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>18</td>\n",
" <td>11</td>\n",
" <td>122</td>\n",
" <td>3</td>\n",
" <td>126</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>56</td>\n",
" <td>26</td>\n",
" <td>106</td>\n",
" <td>14</td>\n",
" <td>139</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>3</td>\n",
" <td>137</td>\n",
" <td>75</td>\n",
" <td>67</td>\n",
" <td>144</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>35</td>\n",
" <td>47</td>\n",
" <td>102</td>\n",
" <td>60</td>\n",
" <td>63</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>86</td>\n",
" <td>126</td>\n",
" <td>57</td>\n",
" <td>88</td>\n",
" <td>149</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>19</td>\n",
" <td>140</td>\n",
" <td>30</td>\n",
" <td>35</td>\n",
" <td>33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>76</td>\n",
" <td>1</td>\n",
" <td>5</td>\n",
" <td>11</td>\n",
" <td>33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>31</td>\n",
" <td>54</td>\n",
" <td>91</td>\n",
" <td>119</td>\n",
" <td>69</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>64</td>\n",
" <td>37</td>\n",
" <td>50</td>\n",
" <td>23</td>\n",
" <td>21</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>72</td>\n",
" <td>57</td>\n",
" <td>138</td>\n",
" <td>15</td>\n",
" <td>21</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>55</td>\n",
" <td>120</td>\n",
" <td>104</td>\n",
" <td>32</td>\n",
" <td>25</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>96</td>\n",
" <td>24</td>\n",
" <td>89</td>\n",
" <td>22</td>\n",
" <td>146</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>63</td>\n",
" <td>0</td>\n",
" <td>8</td>\n",
" <td>64</td>\n",
" <td>89</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>28</td>\n",
" <td>46</td>\n",
" <td>125</td>\n",
" <td>82</td>\n",
" <td>74</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>85</td>\n",
" <td>39</td>\n",
" <td>70</td>\n",
" <td>132</td>\n",
" <td>111</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>109</td>\n",
" <td>90</td>\n",
" <td>44</td>\n",
" <td>74</td>\n",
" <td>39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>2</td>\n",
" <td>148</td>\n",
" <td>103</td>\n",
" <td>114</td>\n",
" <td>65</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>110</td>\n",
" <td>29</td>\n",
" <td>99</td>\n",
" <td>80</td>\n",
" <td>57</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>109</td>\n",
" <td>88</td>\n",
" <td>81</td>\n",
" <td>135</td>\n",
" <td>71</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>70</td>\n",
" <td>103</td>\n",
" <td>134</td>\n",
" <td>121</td>\n",
" <td>121</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>51</td>\n",
" <td>92</td>\n",
" <td>117</td>\n",
" <td>27</td>\n",
" <td>43</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>6</td>\n",
" <td>92</td>\n",
" <td>97</td>\n",
" <td>59</td>\n",
" <td>105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>65</td>\n",
" <td>90</td>\n",
" <td>52</td>\n",
" <td>148</td>\n",
" <td>22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>128</th>\n",
" <td>4</td>\n",
" <td>129</td>\n",
" <td>17</td>\n",
" <td>119</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>129</th>\n",
" <td>24</td>\n",
" <td>100</td>\n",
" <td>107</td>\n",
" <td>28</td>\n",
" <td>139</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2070</th>\n",
" <td>127</td>\n",
" <td>77</td>\n",
" <td>24</td>\n",
" <td>16</td>\n",
" <td>31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2071</th>\n",
" <td>93</td>\n",
" <td>61</td>\n",
" <td>9</td>\n",
" <td>28</td>\n",
" <td>22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2072</th>\n",
" <td>116</td>\n",
" <td>61</td>\n",
" <td>54</td>\n",
" <td>8</td>\n",
" <td>61</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2073</th>\n",
" <td>4</td>\n",
" <td>72</td>\n",
" <td>140</td>\n",
" <td>112</td>\n",
" <td>34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2074</th>\n",
" <td>26</td>\n",
" <td>108</td>\n",
" <td>123</td>\n",
" <td>32</td>\n",
" <td>33</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2075</th>\n",
" <td>46</td>\n",
" <td>130</td>\n",
" <td>135</td>\n",
" <td>124</td>\n",
" <td>113</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2076</th>\n",
" <td>33</td>\n",
" <td>18</td>\n",
" <td>136</td>\n",
" <td>38</td>\n",
" <td>20</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2077</th>\n",
" <td>107</td>\n",
" <td>11</td>\n",
" <td>129</td>\n",
" <td>54</td>\n",
" <td>119</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2078</th>\n",
" <td>84</td>\n",
" <td>55</td>\n",
" <td>129</td>\n",
" <td>37</td>\n",
" <td>87</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2079</th>\n",
" <td>95</td>\n",
" <td>50</td>\n",
" <td>45</td>\n",
" <td>19</td>\n",
" <td>84</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2080</th>\n",
" <td>124</td>\n",
" <td>74</td>\n",
" <td>65</td>\n",
" <td>140</td>\n",
" <td>53</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2081</th>\n",
" <td>26</td>\n",
" <td>35</td>\n",
" <td>149</td>\n",
" <td>145</td>\n",
" <td>127</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2082</th>\n",
" <td>19</td>\n",
" <td>21</td>\n",
" <td>101</td>\n",
" <td>3</td>\n",
" <td>89</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2083</th>\n",
" <td>84</td>\n",
" <td>10</td>\n",
" <td>131</td>\n",
" <td>71</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2084</th>\n",
" <td>28</td>\n",
" <td>74</td>\n",
" <td>105</td>\n",
" <td>68</td>\n",
" <td>89</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2085</th>\n",
" <td>23</td>\n",
" <td>93</td>\n",
" <td>84</td>\n",
" <td>97</td>\n",
" <td>88</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2086</th>\n",
" <td>86</td>\n",
" <td>133</td>\n",
" <td>26</td>\n",
" <td>125</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2087</th>\n",
" <td>21</td>\n",
" <td>124</td>\n",
" <td>40</td>\n",
" <td>115</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2088</th>\n",
" <td>20</td>\n",
" <td>15</td>\n",
" <td>35</td>\n",
" <td>31</td>\n",
" <td>37</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2089</th>\n",
" <td>96</td>\n",
" <td>123</td>\n",
" <td>123</td>\n",
" <td>5</td>\n",
" <td>64</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2090</th>\n",
" <td>22</td>\n",
" <td>43</td>\n",
" <td>92</td>\n",
" <td>78</td>\n",
" <td>60</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2091</th>\n",
" <td>16</td>\n",
" <td>31</td>\n",
" <td>17</td>\n",
" <td>60</td>\n",
" <td>58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2092</th>\n",
" <td>65</td>\n",
" <td>18</td>\n",
" <td>13</td>\n",
" <td>13</td>\n",
" <td>34</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2093</th>\n",
" <td>69</td>\n",
" <td>49</td>\n",
" <td>109</td>\n",
" <td>40</td>\n",
" <td>58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2094</th>\n",
" <td>128</td>\n",
" <td>46</td>\n",
" <td>10</td>\n",
" <td>82</td>\n",
" <td>111</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2095</th>\n",
" <td>26</td>\n",
" <td>59</td>\n",
" <td>8</td>\n",
" <td>54</td>\n",
" <td>149</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2096</th>\n",
" <td>111</td>\n",
" <td>47</td>\n",
" <td>90</td>\n",
" <td>92</td>\n",
" <td>66</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2097</th>\n",
" <td>5</td>\n",
" <td>97</td>\n",
" <td>73</td>\n",
" <td>140</td>\n",
" <td>104</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2098</th>\n",
" <td>102</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>5</td>\n",
" <td>119</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2099</th>\n",
" <td>97</td>\n",
" <td>19</td>\n",
" <td>77</td>\n",
" <td>143</td>\n",
" <td>48</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>2000 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 82 89 99 101 125\n",
"101 4 31 109 32 5\n",
"102 56 103 56 61 90\n",
"103 47 100 147 138 99\n",
"104 38 46 82 75 44\n",
"105 18 11 122 3 126\n",
"106 56 26 106 14 139\n",
"107 3 137 75 67 144\n",
"108 35 47 102 60 63\n",
"109 86 126 57 88 149\n",
"110 19 140 30 35 33\n",
"111 76 1 5 11 33\n",
"112 31 54 91 119 69\n",
"113 64 37 50 23 21\n",
"114 72 57 138 15 21\n",
"115 55 120 104 32 25\n",
"116 96 24 89 22 146\n",
"117 63 0 8 64 89\n",
"118 28 46 125 82 74\n",
"119 85 39 70 132 111\n",
"120 109 90 44 74 39\n",
"121 2 148 103 114 65\n",
"122 110 29 99 80 57\n",
"123 109 88 81 135 71\n",
"124 70 103 134 121 121\n",
"125 51 92 117 27 43\n",
"126 6 92 97 59 105\n",
"127 65 90 52 148 22\n",
"128 4 129 17 119 13\n",
"129 24 100 107 28 139\n",
"... ... ... ... ... ...\n",
"2070 127 77 24 16 31\n",
"2071 93 61 9 28 22\n",
"2072 116 61 54 8 61\n",
"2073 4 72 140 112 34\n",
"2074 26 108 123 32 33\n",
"2075 46 130 135 124 113\n",
"2076 33 18 136 38 20\n",
"2077 107 11 129 54 119\n",
"2078 84 55 129 37 87\n",
"2079 95 50 45 19 84\n",
"2080 124 74 65 140 53\n",
"2081 26 35 149 145 127\n",
"2082 19 21 101 3 89\n",
"2083 84 10 131 71 4\n",
"2084 28 74 105 68 89\n",
"2085 23 93 84 97 88\n",
"2086 86 133 26 125 13\n",
"2087 21 124 40 115 5\n",
"2088 20 15 35 31 37\n",
"2089 96 123 123 5 64\n",
"2090 22 43 92 78 60\n",
"2091 16 31 17 60 58\n",
"2092 65 18 13 13 34\n",
"2093 69 49 109 40 58\n",
"2094 128 46 10 82 111\n",
"2095 26 59 8 54 149\n",
"2096 111 47 90 92 66\n",
"2097 5 97 73 140 104\n",
"2098 102 6 7 5 119\n",
"2099 97 19 77 143 48\n",
"\n",
"[2000 rows x 5 columns]"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = DataFrame(np.random.randint(0,150,size = (2000,5)),index = np.arange(100,2100),columns=['Python','En','Math','Physic','Chem'])\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"for i in range(1000):\n",
" # 行索引\n",
" index = np.random.randint(100,2100,size =1)[0]\n",
"\n",
" cols = df.columns\n",
"\n",
" # 列索引\n",
" col = np.random.choice(cols)\n",
"\n",
" df.loc[index,col] = None"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python 190\n",
"En 200\n",
"Math 194\n",
"Physic 189\n",
"Chem 181\n",
"dtype: int64"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>82.0</td>\n",
" <td>89.0</td>\n",
" <td>99.0</td>\n",
" <td>101.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>4.0</td>\n",
" <td>31.0</td>\n",
" <td>109.0</td>\n",
" <td>32.0</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>56.0</td>\n",
" <td>103.0</td>\n",
" <td>56.0</td>\n",
" <td>NaN</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>47.0</td>\n",
" <td>100.0</td>\n",
" <td>147.0</td>\n",
" <td>138.0</td>\n",
" <td>99.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>38.0</td>\n",
" <td>46.0</td>\n",
" <td>NaN</td>\n",
" <td>75.0</td>\n",
" <td>44.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 82.0 89.0 99.0 101.0 125.0\n",
"101 4.0 31.0 109.0 32.0 5.0\n",
"102 56.0 103.0 56.0 NaN 90.0\n",
"103 47.0 100.0 147.0 138.0 99.0\n",
"104 38.0 46.0 NaN 75.0 44.0"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2095</th>\n",
" <td>26.0</td>\n",
" <td>59.0</td>\n",
" <td>8.0</td>\n",
" <td>54.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2096</th>\n",
" <td>NaN</td>\n",
" <td>47.0</td>\n",
" <td>90.0</td>\n",
" <td>92.0</td>\n",
" <td>66.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2097</th>\n",
" <td>5.0</td>\n",
" <td>97.0</td>\n",
" <td>73.0</td>\n",
" <td>140.0</td>\n",
" <td>104.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2098</th>\n",
" <td>102.0</td>\n",
" <td>6.0</td>\n",
" <td>7.0</td>\n",
" <td>5.0</td>\n",
" <td>119.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2099</th>\n",
" <td>97.0</td>\n",
" <td>19.0</td>\n",
" <td>77.0</td>\n",
" <td>NaN</td>\n",
" <td>48.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"2095 26.0 59.0 8.0 54.0 149.0\n",
"2096 NaN 47.0 90.0 92.0 66.0\n",
"2097 5.0 97.0 73.0 140.0 104.0\n",
"2098 102.0 6.0 7.0 5.0 119.0\n",
"2099 97.0 19.0 77.0 NaN 48.0"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.tail()"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 82., 4., 56., 47., 38., 18., 3., 35., 86., 19., 76.,\n",
" 31., 64., 72., 55., 96., 63., 28., 85., 109., 2., 110.,\n",
" 70., 51., 6., 65., 24., 48., 44., 11., 114., 129., 87.,\n",
" 108., 125., nan, 140., 132., 91., 34., 54., 30., 12., 98.,\n",
" 142., 79., 13., 77., 40., 139., 39., 81., 112., 36., 22.,\n",
" 5., 120., 17., 127., 119., 59., 146., 89., 103., 8., 97.,\n",
" 130., 73., 83., 122., 95., 100., 41., 21., 136., 80., 101.,\n",
" 50., 27., 71., 16., 141., 126., 102., 145., 15., 52., 94.,\n",
" 10., 33., 137., 9., 128., 88., 26., 84., 93., 1., 7.,\n",
" 131., 107., 148., 0., 105., 66., 32., 115., 118., 58., 53.,\n",
" 29., 42., 57., 62., 25., 60., 69., 133., 68., 20., 106.,\n",
" 147., 78., 90., 124., 149., 92., 75., 117., 143., 99., 37.,\n",
" 123., 45., 61., 121., 135., 138., 116., 14., 104., 74., 46.,\n",
" 111., 23., 43., 49., 144., 113., 67., 134.])"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 去重之后的数据\n",
"df['Python'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"143.0 20\n",
"136.0 20\n",
"102.0 19\n",
"105.0 19\n",
"26.0 19\n",
"69.0 19\n",
"31.0 18\n",
"148.0 18\n",
"75.0 18\n",
"139.0 18\n",
"1.0 18\n",
"35.0 17\n",
"140.0 17\n",
"110.0 17\n",
"125.0 17\n",
"146.0 17\n",
"141.0 17\n",
"64.0 16\n",
"30.0 16\n",
"79.0 16\n",
"73.0 16\n",
"40.0 16\n",
"10.0 15\n",
"6.0 15\n",
"65.0 15\n",
"81.0 15\n",
"28.0 15\n",
"48.0 15\n",
"92.0 15\n",
"103.0 15\n",
" ..\n",
"104.0 9\n",
"12.0 9\n",
"116.0 9\n",
"13.0 9\n",
"59.0 9\n",
"93.0 9\n",
"124.0 9\n",
"85.0 8\n",
"135.0 8\n",
"131.0 8\n",
"68.0 8\n",
"66.0 8\n",
"62.0 8\n",
"120.0 8\n",
"17.0 8\n",
"25.0 8\n",
"145.0 7\n",
"58.0 7\n",
"134.0 7\n",
"113.0 7\n",
"123.0 7\n",
"39.0 7\n",
"34.0 7\n",
"43.0 7\n",
"74.0 6\n",
"144.0 6\n",
"132.0 6\n",
"142.0 5\n",
"67.0 5\n",
"49.0 5\n",
"Name: Python, Length: 150, dtype: int64"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Python'].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"8.0 21\n",
"96.0 19\n",
"118.0 19\n",
"24.0 19\n",
"43.0 19\n",
"27.0 19\n",
"19.0 19\n",
"41.0 18\n",
"0.0 18\n",
"3.0 18\n",
"52.0 18\n",
"4.0 17\n",
"137.0 17\n",
"1.0 17\n",
"101.0 17\n",
"51.0 17\n",
"39.0 17\n",
"100.0 17\n",
"127.0 17\n",
"115.0 16\n",
"33.0 16\n",
"112.0 16\n",
"92.0 16\n",
"126.0 16\n",
"133.0 15\n",
"32.0 15\n",
"89.0 15\n",
"95.0 15\n",
"36.0 15\n",
"93.0 15\n",
" ..\n",
"12.0 9\n",
"28.0 9\n",
"106.0 9\n",
"45.0 9\n",
"80.0 9\n",
"84.0 9\n",
"58.0 9\n",
"79.0 9\n",
"71.0 9\n",
"83.0 9\n",
"142.0 9\n",
"7.0 9\n",
"6.0 8\n",
"61.0 8\n",
"149.0 8\n",
"34.0 8\n",
"20.0 8\n",
"38.0 8\n",
"130.0 8\n",
"104.0 7\n",
"120.0 7\n",
"56.0 7\n",
"146.0 7\n",
"98.0 7\n",
"134.0 6\n",
"123.0 6\n",
"35.0 6\n",
"87.0 5\n",
"42.0 5\n",
"119.0 4\n",
"Name: En, Length: 150, dtype: int64"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"en = df['En'].value_counts()\n",
"en"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8.0"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"en.index[0]"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Python 75.0\n",
"En 74.0\n",
"Math 77.5\n",
"Physic 73.0\n",
"Chem 72.0\n",
"dtype: float64 <class 'pandas.core.series.Series'>\n"
]
}
],
"source": [
"s = df.median()\n",
"print(s,type(s))"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
"zhongshu = []\n",
"for col in df.columns:\n",
" zhongshu.append(df[col].value_counts().index[0])"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Python 143.0\n",
"En 8.0\n",
"Math 80.0\n",
"Physic 31.0\n",
"Chem 125.0\n",
"dtype: float64"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = Series(zhongshu,index = df.columns)\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>82.0</td>\n",
" <td>89.0</td>\n",
" <td>99.0</td>\n",
" <td>101.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>4.0</td>\n",
" <td>31.0</td>\n",
" <td>109.0</td>\n",
" <td>32.0</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>56.0</td>\n",
" <td>103.0</td>\n",
" <td>56.0</td>\n",
" <td>31.0</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>47.0</td>\n",
" <td>100.0</td>\n",
" <td>147.0</td>\n",
" <td>138.0</td>\n",
" <td>99.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>38.0</td>\n",
" <td>46.0</td>\n",
" <td>80.0</td>\n",
" <td>75.0</td>\n",
" <td>44.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>18.0</td>\n",
" <td>11.0</td>\n",
" <td>122.0</td>\n",
" <td>3.0</td>\n",
" <td>126.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>56.0</td>\n",
" <td>26.0</td>\n",
" <td>106.0</td>\n",
" <td>14.0</td>\n",
" <td>139.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>3.0</td>\n",
" <td>137.0</td>\n",
" <td>75.0</td>\n",
" <td>67.0</td>\n",
" <td>144.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>35.0</td>\n",
" <td>47.0</td>\n",
" <td>102.0</td>\n",
" <td>60.0</td>\n",
" <td>63.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>86.0</td>\n",
" <td>126.0</td>\n",
" <td>80.0</td>\n",
" <td>88.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>19.0</td>\n",
" <td>140.0</td>\n",
" <td>80.0</td>\n",
" <td>35.0</td>\n",
" <td>33.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>76.0</td>\n",
" <td>8.0</td>\n",
" <td>5.0</td>\n",
" <td>11.0</td>\n",
" <td>33.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>31.0</td>\n",
" <td>54.0</td>\n",
" <td>91.0</td>\n",
" <td>119.0</td>\n",
" <td>69.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>64.0</td>\n",
" <td>37.0</td>\n",
" <td>50.0</td>\n",
" <td>23.0</td>\n",
" <td>21.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>72.0</td>\n",
" <td>57.0</td>\n",
" <td>138.0</td>\n",
" <td>15.0</td>\n",
" <td>21.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>55.0</td>\n",
" <td>120.0</td>\n",
" <td>104.0</td>\n",
" <td>32.0</td>\n",
" <td>25.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>96.0</td>\n",
" <td>24.0</td>\n",
" <td>89.0</td>\n",
" <td>31.0</td>\n",
" <td>146.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>63.0</td>\n",
" <td>8.0</td>\n",
" <td>8.0</td>\n",
" <td>64.0</td>\n",
" <td>89.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>28.0</td>\n",
" <td>8.0</td>\n",
" <td>125.0</td>\n",
" <td>82.0</td>\n",
" <td>74.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>85.0</td>\n",
" <td>39.0</td>\n",
" <td>70.0</td>\n",
" <td>132.0</td>\n",
" <td>111.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>120</th>\n",
" <td>109.0</td>\n",
" <td>90.0</td>\n",
" <td>80.0</td>\n",
" <td>74.0</td>\n",
" <td>39.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>121</th>\n",
" <td>2.0</td>\n",
" <td>8.0</td>\n",
" <td>103.0</td>\n",
" <td>114.0</td>\n",
" <td>65.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>122</th>\n",
" <td>110.0</td>\n",
" <td>29.0</td>\n",
" <td>99.0</td>\n",
" <td>80.0</td>\n",
" <td>57.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>109.0</td>\n",
" <td>88.0</td>\n",
" <td>81.0</td>\n",
" <td>135.0</td>\n",
" <td>71.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>124</th>\n",
" <td>70.0</td>\n",
" <td>103.0</td>\n",
" <td>134.0</td>\n",
" <td>121.0</td>\n",
" <td>121.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>125</th>\n",
" <td>51.0</td>\n",
" <td>92.0</td>\n",
" <td>117.0</td>\n",
" <td>31.0</td>\n",
" <td>43.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>126</th>\n",
" <td>6.0</td>\n",
" <td>92.0</td>\n",
" <td>97.0</td>\n",
" <td>59.0</td>\n",
" <td>105.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>65.0</td>\n",
" <td>90.0</td>\n",
" <td>52.0</td>\n",
" <td>148.0</td>\n",
" <td>22.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>128</th>\n",
" <td>4.0</td>\n",
" <td>129.0</td>\n",
" <td>17.0</td>\n",
" <td>119.0</td>\n",
" <td>13.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>129</th>\n",
" <td>24.0</td>\n",
" <td>100.0</td>\n",
" <td>107.0</td>\n",
" <td>28.0</td>\n",
" <td>139.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2070</th>\n",
" <td>127.0</td>\n",
" <td>77.0</td>\n",
" <td>24.0</td>\n",
" <td>16.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2071</th>\n",
" <td>93.0</td>\n",
" <td>61.0</td>\n",
" <td>9.0</td>\n",
" <td>28.0</td>\n",
" <td>22.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2072</th>\n",
" <td>116.0</td>\n",
" <td>61.0</td>\n",
" <td>54.0</td>\n",
" <td>8.0</td>\n",
" <td>61.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2073</th>\n",
" <td>4.0</td>\n",
" <td>72.0</td>\n",
" <td>140.0</td>\n",
" <td>31.0</td>\n",
" <td>34.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2074</th>\n",
" <td>143.0</td>\n",
" <td>108.0</td>\n",
" <td>123.0</td>\n",
" <td>32.0</td>\n",
" <td>33.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2075</th>\n",
" <td>46.0</td>\n",
" <td>8.0</td>\n",
" <td>135.0</td>\n",
" <td>124.0</td>\n",
" <td>113.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2076</th>\n",
" <td>143.0</td>\n",
" <td>18.0</td>\n",
" <td>136.0</td>\n",
" <td>38.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2077</th>\n",
" <td>143.0</td>\n",
" <td>11.0</td>\n",
" <td>129.0</td>\n",
" <td>54.0</td>\n",
" <td>119.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2078</th>\n",
" <td>84.0</td>\n",
" <td>55.0</td>\n",
" <td>129.0</td>\n",
" <td>37.0</td>\n",
" <td>87.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2079</th>\n",
" <td>95.0</td>\n",
" <td>50.0</td>\n",
" <td>45.0</td>\n",
" <td>19.0</td>\n",
" <td>84.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2080</th>\n",
" <td>124.0</td>\n",
" <td>74.0</td>\n",
" <td>65.0</td>\n",
" <td>31.0</td>\n",
" <td>53.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2081</th>\n",
" <td>26.0</td>\n",
" <td>35.0</td>\n",
" <td>149.0</td>\n",
" <td>145.0</td>\n",
" <td>127.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2082</th>\n",
" <td>19.0</td>\n",
" <td>21.0</td>\n",
" <td>101.0</td>\n",
" <td>3.0</td>\n",
" <td>89.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2083</th>\n",
" <td>84.0</td>\n",
" <td>8.0</td>\n",
" <td>131.0</td>\n",
" <td>71.0</td>\n",
" <td>4.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2084</th>\n",
" <td>28.0</td>\n",
" <td>74.0</td>\n",
" <td>105.0</td>\n",
" <td>68.0</td>\n",
" <td>89.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2085</th>\n",
" <td>23.0</td>\n",
" <td>93.0</td>\n",
" <td>84.0</td>\n",
" <td>97.0</td>\n",
" <td>88.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2086</th>\n",
" <td>86.0</td>\n",
" <td>133.0</td>\n",
" <td>26.0</td>\n",
" <td>125.0</td>\n",
" <td>13.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2087</th>\n",
" <td>21.0</td>\n",
" <td>124.0</td>\n",
" <td>40.0</td>\n",
" <td>31.0</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2088</th>\n",
" <td>20.0</td>\n",
" <td>15.0</td>\n",
" <td>35.0</td>\n",
" <td>31.0</td>\n",
" <td>37.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2089</th>\n",
" <td>96.0</td>\n",
" <td>123.0</td>\n",
" <td>123.0</td>\n",
" <td>5.0</td>\n",
" <td>64.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2090</th>\n",
" <td>22.0</td>\n",
" <td>43.0</td>\n",
" <td>92.0</td>\n",
" <td>78.0</td>\n",
" <td>60.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2091</th>\n",
" <td>16.0</td>\n",
" <td>31.0</td>\n",
" <td>17.0</td>\n",
" <td>60.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2092</th>\n",
" <td>65.0</td>\n",
" <td>18.0</td>\n",
" <td>13.0</td>\n",
" <td>13.0</td>\n",
" <td>34.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2093</th>\n",
" <td>69.0</td>\n",
" <td>49.0</td>\n",
" <td>109.0</td>\n",
" <td>40.0</td>\n",
" <td>58.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2094</th>\n",
" <td>128.0</td>\n",
" <td>46.0</td>\n",
" <td>10.0</td>\n",
" <td>82.0</td>\n",
" <td>111.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2095</th>\n",
" <td>26.0</td>\n",
" <td>59.0</td>\n",
" <td>8.0</td>\n",
" <td>54.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2096</th>\n",
" <td>143.0</td>\n",
" <td>47.0</td>\n",
" <td>90.0</td>\n",
" <td>92.0</td>\n",
" <td>66.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2097</th>\n",
" <td>5.0</td>\n",
" <td>97.0</td>\n",
" <td>73.0</td>\n",
" <td>140.0</td>\n",
" <td>104.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2098</th>\n",
" <td>102.0</td>\n",
" <td>6.0</td>\n",
" <td>7.0</td>\n",
" <td>5.0</td>\n",
" <td>119.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2099</th>\n",
" <td>97.0</td>\n",
" <td>19.0</td>\n",
" <td>77.0</td>\n",
" <td>31.0</td>\n",
" <td>48.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>2000 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 82.0 89.0 99.0 101.0 125.0\n",
"101 4.0 31.0 109.0 32.0 5.0\n",
"102 56.0 103.0 56.0 31.0 90.0\n",
"103 47.0 100.0 147.0 138.0 99.0\n",
"104 38.0 46.0 80.0 75.0 44.0\n",
"105 18.0 11.0 122.0 3.0 126.0\n",
"106 56.0 26.0 106.0 14.0 139.0\n",
"107 3.0 137.0 75.0 67.0 144.0\n",
"108 35.0 47.0 102.0 60.0 63.0\n",
"109 86.0 126.0 80.0 88.0 149.0\n",
"110 19.0 140.0 80.0 35.0 33.0\n",
"111 76.0 8.0 5.0 11.0 33.0\n",
"112 31.0 54.0 91.0 119.0 69.0\n",
"113 64.0 37.0 50.0 23.0 21.0\n",
"114 72.0 57.0 138.0 15.0 21.0\n",
"115 55.0 120.0 104.0 32.0 25.0\n",
"116 96.0 24.0 89.0 31.0 146.0\n",
"117 63.0 8.0 8.0 64.0 89.0\n",
"118 28.0 8.0 125.0 82.0 74.0\n",
"119 85.0 39.0 70.0 132.0 111.0\n",
"120 109.0 90.0 80.0 74.0 39.0\n",
"121 2.0 8.0 103.0 114.0 65.0\n",
"122 110.0 29.0 99.0 80.0 57.0\n",
"123 109.0 88.0 81.0 135.0 71.0\n",
"124 70.0 103.0 134.0 121.0 121.0\n",
"125 51.0 92.0 117.0 31.0 43.0\n",
"126 6.0 92.0 97.0 59.0 105.0\n",
"127 65.0 90.0 52.0 148.0 22.0\n",
"128 4.0 129.0 17.0 119.0 13.0\n",
"129 24.0 100.0 107.0 28.0 139.0\n",
"... ... ... ... ... ...\n",
"2070 127.0 77.0 24.0 16.0 125.0\n",
"2071 93.0 61.0 9.0 28.0 22.0\n",
"2072 116.0 61.0 54.0 8.0 61.0\n",
"2073 4.0 72.0 140.0 31.0 34.0\n",
"2074 143.0 108.0 123.0 32.0 33.0\n",
"2075 46.0 8.0 135.0 124.0 113.0\n",
"2076 143.0 18.0 136.0 38.0 125.0\n",
"2077 143.0 11.0 129.0 54.0 119.0\n",
"2078 84.0 55.0 129.0 37.0 87.0\n",
"2079 95.0 50.0 45.0 19.0 84.0\n",
"2080 124.0 74.0 65.0 31.0 53.0\n",
"2081 26.0 35.0 149.0 145.0 127.0\n",
"2082 19.0 21.0 101.0 3.0 89.0\n",
"2083 84.0 8.0 131.0 71.0 4.0\n",
"2084 28.0 74.0 105.0 68.0 89.0\n",
"2085 23.0 93.0 84.0 97.0 88.0\n",
"2086 86.0 133.0 26.0 125.0 13.0\n",
"2087 21.0 124.0 40.0 31.0 5.0\n",
"2088 20.0 15.0 35.0 31.0 37.0\n",
"2089 96.0 123.0 123.0 5.0 64.0\n",
"2090 22.0 43.0 92.0 78.0 60.0\n",
"2091 16.0 31.0 17.0 60.0 58.0\n",
"2092 65.0 18.0 13.0 13.0 34.0\n",
"2093 69.0 49.0 109.0 40.0 58.0\n",
"2094 128.0 46.0 10.0 82.0 111.0\n",
"2095 26.0 59.0 8.0 54.0 149.0\n",
"2096 143.0 47.0 90.0 92.0 66.0\n",
"2097 5.0 97.0 73.0 140.0 104.0\n",
"2098 102.0 6.0 7.0 5.0 119.0\n",
"2099 97.0 19.0 77.0 31.0 48.0\n",
"\n",
"[2000 rows x 5 columns]"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2 = df.fillna(s)\n",
"df2"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python 0\n",
"En 0\n",
"Math 0\n",
"Physic 0\n",
"Chem 0\n",
"dtype: int64"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df2.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/plain": [
"Python 190\n",
"En 200\n",
"Math 194\n",
"Physic 189\n",
"Chem 181\n",
"dtype: int64"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>82.0</td>\n",
" <td>89.0</td>\n",
" <td>99.0</td>\n",
" <td>101.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>4.0</td>\n",
" <td>31.0</td>\n",
" <td>109.0</td>\n",
" <td>32.0</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>56.0</td>\n",
" <td>103.0</td>\n",
" <td>56.0</td>\n",
" <td>NaN</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>47.0</td>\n",
" <td>100.0</td>\n",
" <td>147.0</td>\n",
" <td>138.0</td>\n",
" <td>99.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>38.0</td>\n",
" <td>46.0</td>\n",
" <td>NaN</td>\n",
" <td>75.0</td>\n",
" <td>44.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>18.0</td>\n",
" <td>11.0</td>\n",
" <td>122.0</td>\n",
" <td>3.0</td>\n",
" <td>126.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>56.0</td>\n",
" <td>26.0</td>\n",
" <td>106.0</td>\n",
" <td>14.0</td>\n",
" <td>139.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>3.0</td>\n",
" <td>137.0</td>\n",
" <td>75.0</td>\n",
" <td>67.0</td>\n",
" <td>144.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>35.0</td>\n",
" <td>47.0</td>\n",
" <td>102.0</td>\n",
" <td>60.0</td>\n",
" <td>63.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>86.0</td>\n",
" <td>126.0</td>\n",
" <td>NaN</td>\n",
" <td>88.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>19.0</td>\n",
" <td>140.0</td>\n",
" <td>NaN</td>\n",
" <td>35.0</td>\n",
" <td>33.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>76.0</td>\n",
" <td>NaN</td>\n",
" <td>5.0</td>\n",
" <td>11.0</td>\n",
" <td>33.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>31.0</td>\n",
" <td>54.0</td>\n",
" <td>91.0</td>\n",
" <td>119.0</td>\n",
" <td>69.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>64.0</td>\n",
" <td>37.0</td>\n",
" <td>50.0</td>\n",
" <td>23.0</td>\n",
" <td>21.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>72.0</td>\n",
" <td>57.0</td>\n",
" <td>138.0</td>\n",
" <td>15.0</td>\n",
" <td>21.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>55.0</td>\n",
" <td>120.0</td>\n",
" <td>104.0</td>\n",
" <td>32.0</td>\n",
" <td>25.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>96.0</td>\n",
" <td>24.0</td>\n",
" <td>89.0</td>\n",
" <td>NaN</td>\n",
" <td>146.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>63.0</td>\n",
" <td>NaN</td>\n",
" <td>8.0</td>\n",
" <td>64.0</td>\n",
" <td>89.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>28.0</td>\n",
" <td>NaN</td>\n",
" <td>125.0</td>\n",
" <td>82.0</td>\n",
" <td>74.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>85.0</td>\n",
" <td>39.0</td>\n",
" <td>70.0</td>\n",
" <td>132.0</td>\n",
" <td>111.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 82.0 89.0 99.0 101.0 125.0\n",
"101 4.0 31.0 109.0 32.0 5.0\n",
"102 56.0 103.0 56.0 NaN 90.0\n",
"103 47.0 100.0 147.0 138.0 99.0\n",
"104 38.0 46.0 NaN 75.0 44.0\n",
"105 18.0 11.0 122.0 3.0 126.0\n",
"106 56.0 26.0 106.0 14.0 139.0\n",
"107 3.0 137.0 75.0 67.0 144.0\n",
"108 35.0 47.0 102.0 60.0 63.0\n",
"109 86.0 126.0 NaN 88.0 149.0\n",
"110 19.0 140.0 NaN 35.0 33.0\n",
"111 76.0 NaN 5.0 11.0 33.0\n",
"112 31.0 54.0 91.0 119.0 69.0\n",
"113 64.0 37.0 50.0 23.0 21.0\n",
"114 72.0 57.0 138.0 15.0 21.0\n",
"115 55.0 120.0 104.0 32.0 25.0\n",
"116 96.0 24.0 89.0 NaN 146.0\n",
"117 63.0 NaN 8.0 64.0 89.0\n",
"118 28.0 NaN 125.0 82.0 74.0\n",
"119 85.0 39.0 70.0 132.0 111.0"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df3 = df.iloc[:20]\n",
"df3"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Python</th>\n",
" <th>En</th>\n",
" <th>Math</th>\n",
" <th>Physic</th>\n",
" <th>Chem</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>82.0</td>\n",
" <td>89.0</td>\n",
" <td>99.0</td>\n",
" <td>101.0</td>\n",
" <td>125.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>4.0</td>\n",
" <td>31.0</td>\n",
" <td>109.0</td>\n",
" <td>32.0</td>\n",
" <td>5.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>102</th>\n",
" <td>56.0</td>\n",
" <td>103.0</td>\n",
" <td>56.0</td>\n",
" <td>90.0</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>103</th>\n",
" <td>47.0</td>\n",
" <td>100.0</td>\n",
" <td>147.0</td>\n",
" <td>138.0</td>\n",
" <td>99.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>104</th>\n",
" <td>38.0</td>\n",
" <td>46.0</td>\n",
" <td>75.0</td>\n",
" <td>75.0</td>\n",
" <td>44.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>18.0</td>\n",
" <td>11.0</td>\n",
" <td>122.0</td>\n",
" <td>3.0</td>\n",
" <td>126.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>106</th>\n",
" <td>56.0</td>\n",
" <td>26.0</td>\n",
" <td>106.0</td>\n",
" <td>14.0</td>\n",
" <td>139.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>107</th>\n",
" <td>3.0</td>\n",
" <td>137.0</td>\n",
" <td>75.0</td>\n",
" <td>67.0</td>\n",
" <td>144.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>108</th>\n",
" <td>35.0</td>\n",
" <td>47.0</td>\n",
" <td>102.0</td>\n",
" <td>60.0</td>\n",
" <td>63.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>109</th>\n",
" <td>86.0</td>\n",
" <td>126.0</td>\n",
" <td>88.0</td>\n",
" <td>88.0</td>\n",
" <td>149.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>110</th>\n",
" <td>19.0</td>\n",
" <td>140.0</td>\n",
" <td>35.0</td>\n",
" <td>35.0</td>\n",
" <td>33.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>111</th>\n",
" <td>76.0</td>\n",
" <td>5.0</td>\n",
" <td>5.0</td>\n",
" <td>11.0</td>\n",
" <td>33.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>112</th>\n",
" <td>31.0</td>\n",
" <td>54.0</td>\n",
" <td>91.0</td>\n",
" <td>119.0</td>\n",
" <td>69.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>113</th>\n",
" <td>64.0</td>\n",
" <td>37.0</td>\n",
" <td>50.0</td>\n",
" <td>23.0</td>\n",
" <td>21.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>114</th>\n",
" <td>72.0</td>\n",
" <td>57.0</td>\n",
" <td>138.0</td>\n",
" <td>15.0</td>\n",
" <td>21.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>55.0</td>\n",
" <td>120.0</td>\n",
" <td>104.0</td>\n",
" <td>32.0</td>\n",
" <td>25.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>96.0</td>\n",
" <td>24.0</td>\n",
" <td>89.0</td>\n",
" <td>146.0</td>\n",
" <td>146.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>63.0</td>\n",
" <td>8.0</td>\n",
" <td>8.0</td>\n",
" <td>64.0</td>\n",
" <td>89.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>28.0</td>\n",
" <td>125.0</td>\n",
" <td>125.0</td>\n",
" <td>82.0</td>\n",
" <td>74.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>85.0</td>\n",
" <td>39.0</td>\n",
" <td>70.0</td>\n",
" <td>132.0</td>\n",
" <td>111.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Python En Math Physic Chem\n",
"100 82.0 89.0 99.0 101.0 125.0\n",
"101 4.0 31.0 109.0 32.0 5.0\n",
"102 56.0 103.0 56.0 90.0 90.0\n",
"103 47.0 100.0 147.0 138.0 99.0\n",
"104 38.0 46.0 75.0 75.0 44.0\n",
"105 18.0 11.0 122.0 3.0 126.0\n",
"106 56.0 26.0 106.0 14.0 139.0\n",
"107 3.0 137.0 75.0 67.0 144.0\n",
"108 35.0 47.0 102.0 60.0 63.0\n",
"109 86.0 126.0 88.0 88.0 149.0\n",
"110 19.0 140.0 35.0 35.0 33.0\n",
"111 76.0 5.0 5.0 11.0 33.0\n",
"112 31.0 54.0 91.0 119.0 69.0\n",
"113 64.0 37.0 50.0 23.0 21.0\n",
"114 72.0 57.0 138.0 15.0 21.0\n",
"115 55.0 120.0 104.0 32.0 25.0\n",
"116 96.0 24.0 89.0 146.0 146.0\n",
"117 63.0 8.0 8.0 64.0 89.0\n",
"118 28.0 125.0 125.0 82.0 74.0\n",
"119 85.0 39.0 70.0 132.0 111.0"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'''method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None\n",
" Method to use for filling holes in reindexed Series\n",
" pad / ffill: propagate last valid observation forward to next valid\n",
" backfill / bfill: use NEXT valid observation to fill gap'''\n",
"df3.fillna(method='bfill',axis = 1)"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(2000, 5)"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#数据量足够大,空数据比较少,直接删除\n",
"df.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.dro"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}