<!-- markdown css tag --><section id="nice" data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px; color: black; padding: 0 10px; line-height: 1.6; word-spacing: 0px; letter-spacing: 0px; word-break: break-word; word-wrap: break-word; text-align: left; font-family: PingFangSC-Light;"><figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://file.haoxueai.cn/haoxue/img/ca9b1215-d0c3-4880-90bb-9633fa75600f.png" alt="数据预处理概念图" style="max-width: 100%; border-radius: 0px 0px 5px 5px; display: block; margin: 20px auto; width: 85%; height: 100%; ob ject-fit: contain; box-shadow: #84A1A8 0px 10px 15px;"><figcaption style="margin-top: 5px; text-align: center; color: #888; display: block; font-size: 12px; font-family: PingFangSC-Light;">数据预处理概念图</figcaption></figure>
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">一、引言</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">尽管数据预处理在数据科学和机器学习工作流中具有重要意义,但这些过程往往无法正确执行——主要是因为人们认为它们过于复杂、耗时,或者需要大量自定义代码。因此,从业者可能会推迟数据清理等必要任务,依赖脆弱的临时解决方案(从长远来看不可持续),或者对本质上可能很简单的问题过度设计解决方案。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">本文将介绍8个Python技巧,让你以最小的 effort 将原始、杂乱的数据转换为干净、整齐的预处理数据。</p>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">在查看具体技巧和相应的代码示例之前,以下前置代码会设置必要的库,并定义一个模拟数据集来说明每个技巧:</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;"><span class="hljs-keyword" style="color: #c678dd; line-height: 26px;">import</span> pandas <span class="hljs-keyword" style="color: #c678dd; line-height: 26px;">as</span> pd<br><span class="hljs-keyword" style="color: #c678dd; line-height: 26px;">import</span> numpy <span class="hljs-keyword" style="color: #c678dd; line-height: 26px;">as</span> np<br><span class="hljs-comment" style="color: #5c6370; font-style: italic; line-height: 26px;"># 一个小型的、特意设置得杂乱的数据集</span><br>df = pd.Datafr ame({<br> <span class="hljs-string" style="color: #98c379; line-height: 26px;">" User Name "</span>: [<span class="hljs-string" style="color: #98c379; line-height: 26px;">" Alice "</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"bob"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"Bob"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"alice"</span>, <span class="hljs-literal" style="color: #56b6c2; line-height: 26px;">None</span>],<br> <span class="hljs-string" style="color: #98c379; line-height: 26px;">"Age"</span>: [<span class="hljs-string" style="color: #98c379; line-height: 26px;">"25"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"30"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"?"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"120"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"28"</span>],<br> <span class="hljs-string" style="color: #98c379; line-height: 26px;">"Income$"</span>: [<span class="hljs-string" style="color: #98c379; line-height: 26px;">"50000"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"60000"</span>, <span class="hljs-literal" style="color: #56b6c2; line-height: 26px;">None</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"1000000"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"55000"</span>],<br> <span class="hljs-string" style="color: #98c379; line-height: 26px;">"Join Date"</span>: [<span class="hljs-string" style="color: #98c379; line-height: 26px;">"2023-01-01"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"01/15/2023"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"not a date"</span>, <span class="hljs-literal" style="color: #56b6c2; line-height: 26px;">None</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"2023-02-01"</span>],<br> <span class="hljs-string" style="color: #98c379; line-height: 26px;">"City"</span>: [<span class="hljs-string" style="color: #98c379; line-height: 26px;">"New York"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"new york "</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"NYC"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"New York"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"nyc"</span>],<br>})<br></code></pre>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">二、瞬间标准化列名</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">这是一个非常实用的单行代码技巧:只需一行代码,就能标准化数据集中所有列的名称。具体操作取决于你希望如何标准化属性名称,但以下示例展示了如何将空格替换为下划线,并将所有字符转换为小写,从而确保一致、标准化的命名规范。这对于防止下游任务中出现恼人的错误或修正可能的拼写错误至关重要,无需逐列迭代!</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">df.columns = df.columns.str.strip().str.lower().str.replace(<span class="hljs-string" style="color: #98c379; line-height: 26px;">" "</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"_"</span>)<br></code></pre>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">三、批量去除字符串中的空格</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">有时你可能只想确保系统地移除整个数据集中所有字符串(分类)值开头或结尾的、人眼不可见的无用字符(如空格)。这种方法可以巧妙地对所有包含字符串的列执行此操作,而不改变其他列(如数值列)。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">df = df.apply(<span class="hljs-keyword" style="color: #c678dd; line-height: 26px;">lambda</span> s: s.str.strip() <span class="hljs-keyword" style="color: #c678dd; line-height: 26px;">if</span> s.dtype == <span class="hljs-string" style="color: #98c379; line-height: 26px;">"ob ject"</span> <span class="hljs-keyword" style="color: #c678dd; line-height: 26px;">else</span> s)<br></code></pre>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">四、安全转换数值列</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">如果我们不能100%确定数值列中的所有值都遵循相同的格式,通常最好显式地将这些值转换为数值格式,将有时看起来像数字的杂乱字符串转换为实际的数字。只需一行代码,我们就能完成原本需要try-except块和更手动的清理过程才能实现的功能。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"age"</span>] = pd.to_numeric(df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"age"</span>], errors=<span class="hljs-string" style="color: #98c379; line-height: 26px;">"coerce"</span>)<br>df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"income$"</span>] = pd.to_numeric(df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"income$"</span>], errors=<span class="hljs-string" style="color: #98c379; line-height: 26px;">"coerce"</span>)<br></code></pre>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">注意,其他传统方法(如df['columna'].astype(float))有时会崩溃——如果遇到无法轻松转换为数值的无效原始值。</p>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">五、使用errors='coerce'解析日期</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">这是一种类似的面向验证的过程,但针对不同的数据类型。这个技巧会转换有效的日期时间值,将无效的值设为缺失值。使用errors='coerce'是关键——它告诉Pandas,如果发现无效、无法转换的值,应将其转换为NaT(非时间值),而不是在执行过程中产生错误并崩溃程序。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"join_date"</span>] = pd.to_datetime(df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"join_date"</span>], errors=<span class="hljs-string" style="color: #98c379; line-height: 26px;">"coerce"</span>)<br></code></pre>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">六、使用智能默认值修复缺失值</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">对于那些除了删除包含缺失值的整行之外,不熟悉其他缺失值处理策略的人来说,这种策略会使用统计驱动的默认值(如中位数或众数)来填充这些缺失值。这是一种高效的、基于单行代码的策略,可以通过不同的默认聚合函数进行调整。众数(mode)后面的[0]索引用于在两个或多个“最频繁值”出现平局时,仅获取一个值。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"age"</span>] = df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"age"</span>].fillna(df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"age"</span>].median())<br>df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"city"</span>] = df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"city"</span>].fillna(df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"city"</span>].mode()[<span class="hljs-number" style="color: #d19a66; line-height: 26px;">0</span>])<br></code></pre>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">七、使用Map标准化分类值</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">在包含多种值的分类列中(如城市列),标准化名称并消除可能的不一致性也很有必要——这样可以获得更干净的分组名称,并使下游的分组聚合(如groupby())可靠且有效。在字典的辅助下,以下示例对与纽约市相关的字符串值应用一对一映射,确保所有值都统一表示为“NYC”。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">city_map = {<span class="hljs-string" style="color: #98c379; line-height: 26px;">"new york"</span>: <span class="hljs-string" style="color: #98c379; line-height: 26px;">"NYC"</span>, <span class="hljs-string" style="color: #98c379; line-height: 26px;">"nyc"</span>: <span class="hljs-string" style="color: #98c379; line-height: 26px;">"NYC"</span>}<br>df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"city"</span>] = df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"city"</span>].str.lower().map(city_map).fillna(df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"city"</span>])<br></code></pre>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">八、灵活明智地删除重复项</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">这种高度可定制的重复项删除策略的关键是使用subset=["user_name"]。在这个示例中,它用于告诉Pandas,只有通过查看“user_name”列,并验证该列中的值是否与另一行中的值相同,才能将一行视为重复项。这是确保数据集中每个唯一用户仅出现一次的好方法,可防止重复计数,并且只需一条指令就能完成。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">df = df.drop_duplicates(subset=[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"user_name"</span>])<br></code></pre>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">九、裁剪分位数以去除异常值</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">最后一个技巧是自动限制极端值或异常值,而不是将它们完全删除。例如,当异常值被认为是由于数据中手动引入的错误时,这一点特别有用。裁剪(clipping)会将低于和高于两个分位数(示例中为1%和99%)的极端值设置为这两个分位数的值,而保留位于两个指定分位数之间的原始值不变。简单来说,这就像是将过大或过小的值限制在合理范围内。</p>
<pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #abb2bf; background: #282c34; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; -webkit-overflow-scrolling: touch;">q_low, q_high = df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"income$"</span>].quantile([<span class="hljs-number" style="color: #d19a66; line-height: 26px;">0.01</span>, <span class="hljs-number" style="color: #d19a66; line-height: 26px;">0.99</span>])<br>df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"income$"</span>] = df[<span class="hljs-string" style="color: #98c379; line-height: 26px;">"income$"</span>].clip(q_low, q_high)<br></code></pre>
<hr data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; height: 1px; padding: 0; border: none; border-top: medium solidid #333; text-align: center; background-image: linear-gradient(to right,rgba(248,57,41,0),rgba(248,57,41,0.75),rgba(248,57,41,0));">
<h2 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 22px; text-align: left; margin: 20px 10px 0px 0px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid rgb(248,57,41);">十、总结</span><span class="suffix"></span></h2>
<p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">本文介绍了8个实用的技巧、窍门和策略,将提升你在Python中的数据预处理流水线,使其同时更高效、更有效且更稳健。</p>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 14px; color: rgb(165,213,93);">推荐学习书籍 《<strong style="font-weight: border; color: rgb(248,57,41);">CDA一级教材</strong>》适合CDA一级考生备考,也适合业务及数据分析岗位的从业者提升自我。完整电子版已上线CDA网校,累计已有10万+在读~ !</span><span class="suffix" style="display: none;"></span></h3>
<figure data-tool="mdnice编辑器" style="margin: 0; margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;"><img src="https://file.haoxueai.cn/haoxue/img/4502d41c-fb3a-43a8-bf50-9e14aedde094.png" alt style="max-width: 100%; border-radius: 0px 0px 5px 5px; display: block; margin: 20px auto; width: 85%; height: 100%; ob ject-fit: contain; box-shadow: #84A1A8 0px 10px 15px;"></figure>
<h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; padding: 0px; font-weight: bold; color: black; font-size: 20px;"><span class="prefix" style="display: none;"></span><span class="content" style="font-size: 14px; color: rgb(165,213,93);">免费加入阅读:<a href="https://edu.cda.cn/goods/show/3151?targetId=5147&preview=0" style="text-decoration: none; word-wrap: break-word; font-weight: bold; color: rgb(248,57,41); border-bottom: 1px solid #ff3502; font-family: STHeitiSC-Light;">https://edu.cda.cn/goods/show/3151?targetId=5147&preview=0</a></span><span class="suffix" style="display: none;"></span></h3>
</section>


雷达卡





京公网安备 11010802022788号







