当前位置:

首页 > 编程开发 > Pandas:十种数据处理技巧,让你事半功倍

Pandas:十种数据处理技巧,让你事半功倍

本文所整理的技巧与以前整理过10个Pandas的常用技巧不同,你可能并不会经常的使用它,但是有时候当你遇到一些非常棘手的问题时,这些技巧可以帮你快速解决一些不常见的问题。1、Categorical类型默认情况下,具有有限数量选项的列都会被分配object类型。但是就内存来说并不是一个有效的选择。我们可以这些列建立索引,并仅使用对对象的引用而实际值。Pandas提供了一种称为Categorical的Dtype来解决这个问题。例如一个带有图片路径的大型数据集组成。每行有三列:anchor,pos

本文所整理的技巧与以前整理过10个Pandas的常用技巧不同,你可能并不会经常的使用它,但是有时候当你遇到一些非常棘手的问题时,这些技巧可以帮你快速解决一些不常见的问题。

Pandas:十种数据处理技巧,让你事半功倍

1、Categorical类型

默认情况下,具有有限数量选项的列都会被分配object 类型。 但是就内存来说并不是一个有效的选择。 我们可以这些列建立索引,并仅使用对对象的引用而实际值。Pandas 提供了一种称为 Categorical的Dtype来解决这个问题。

例如一个带有图片路径的大型数据集组成。 每行有三列:anchor, positive, and negative.。

如果类别列使用 Categorical 可以显着减少内存使用量。

# raw data
 +----------+------------------------+
 |class |filename|
 +----------+------------------------+
 | Bathroom | Bathroombath_1.jpg|
 | Bathroom | Bathroombath_100.jpg|
 | Bathroom | Bathroombath_1003.jpg |
 | Bathroom | Bathroombath_1004.jpg |
 | Bathroom | Bathroombath_1005.jpg |
 +----------+------------------------+
 
 # target
 +------------------------+------------------------+----------------------------+
 | anchor |positive|negative|
 +------------------------+------------------------+----------------------------+
 | Bathroombath_1.jpg| Bathroombath_100.jpg| Dinningdin_540.jpg|
 | Bathroombath_100.jpg| Bathroombath_1003.jpg | Dinningdin_1593.jpg |
 | Bathroombath_1003.jpg | Bathroombath_1004.jpg | Bedroombed_329.jpg|
 | Bathroombath_1004.jpg | Bathroombath_1005.jpg | Livingroomliving_1030.jpg |
 | Bathroombath_1005.jpg | Bathroombath_1007.jpg | Bedroombed_1240.jpg |
 +------------------------+------------------------+----------------------------+

filename列的值会经常被复制重复。因此,所以通过使用Categorical可以极大的减少内存使用量。

让我们读取目标数据集,看看内存的差异:

triplets.info(memory_usage="deep")
 
 # Column Non-Null Count Dtype
 # --- ------ -------------- -----
 # 0 anchor 525000 non-null category
 # 1 positive 525000 non-null category
 # 2 negative 525000 non-null category
 # dtypes: category(3)
 # memory usage: 4.6 MB
 
 # without categories
 triplets_raw.info(memory_usage="deep")
 
 # Column Non-Null Count Dtype
 # --- ------ -------------- -----
 # 0 anchor 525000 non-null object
 # 1 positive 525000 non-null object
 # 2 negative 525000 non-null object
 # dtypes: object(3)
 # memory usage: 118.1 MB

差异非常大,并且随着重复次数的增加,差异呈非线性增长。

2、行列转换

sql中经常会遇到行列转换的问题,Pandas有时候也需要,让我们看看来自Kaggle比赛的数据集。census_start .csv文件:

Pandas:十种数据处理技巧,让你事半功倍

可以看到,这些按年来保存的,如果有一个列year和pct_bb,并且每一行有相应的值,则会好得多,对吧。

cols = sorted([col for col in original_df.columns 
 if col.startswith("pct_bb")])
 df = original_df[(["cfips"] + cols)]
 df = df.melt(id_vars="cfips",
value_vars=cols,
var_name="year",
value_name="feature").sort_values(by=["cfips", "year"])

看看结果,这样是不是就好很多了:

Pandas:十种数据处理技巧,让你事半功倍

3、apply()很慢

我们上次已经介绍过,最好不要使用这个方法,因为它遍历每行并调用指定的方法。但是要是我们没有别的选择,那还有没有办法提高速度呢?

可以使用swifter或pandarallew这样的包,使过程并行化。

Swifter

import pandas as pd
 import swifter
 
 def target_function(row):
 return row * 10
 
 def traditional_way(data):
 data['out'] = data['in'].apply(target_function)
 
 def swifter_way(data):
 data['out'] = data['in'].swifter.apply(target_function)

Pandarallel

import pandas as pd
 from pandarallel import pandarallel
 
 def target_function(row):
 return row * 10
 
 def traditional_way(data):
 data['out'] = data['in'].apply(target_function)
 
 def pandarallel_way(data):
 pandarallel.initialize()
 data['out'] = data['in'].parallel_apply(target_function)

通过多线程,可以提高计算的速度,当然当然,如果有集群,那么最好使用dask或pyspark

4、空值,int, Int64

标准整型数据类型不支持空值,所以会自动转换为浮点数。所以如果数据要求在整数字段中使用空值,请考虑使用Int64数据类型,因为它会使用pandas.NA来表示空值。

5、Csv, 压缩还是parquet?

尽可能选择parquet。parquet会保留数据类型,在读取数据时就不需要指定dtypes。parquet文件默认已经使用了snappy进行压缩,所以占用的磁盘空间小。下面可以看看几个的对比

|file|size |
 +------------------------+---------+
 | triplets_525k.csv| 38.4 MB |
 | triplets_525k.csv.gzip |4.3 MB |
 | triplets_525k.csv.zip|4.5 MB |
 | triplets_525k.parquet|1.9 MB |
 +------------------------+---------+

读取parquet需要额外的包,比如pyarrow或fastparquet。chatgpt说pyarrow比fastparquet要快,但是我在小数据集上测试时fastparquet比pyarrow要快,但是这里建议使用pyarrow,因为pandas 2.0也是默认的使用这个。

6、value_counts ()

计算相对频率,包括获得绝对值、计数和除以总数是很复杂的,但是使用value_counts,可以更容易地完成这项任务,并且该方法提供了包含或排除空值的选项。

df = pd.DataFrame({"a": [1, 2, None], "b": [4., 5.1, 14.02]})
 df["a"] = df["a"].astype("Int64")
 print(df.info())
 print(df["a"].value_counts(normalize=True, dropna=False),
df["a"].value_counts(normalize=True, dropna=True), sep="nn")

Pandas:十种数据处理技巧,让你事半功倍

这样是不是就简单很多了

7、Modin

注意:Modin现在还在测试阶段。

pandas是单线程的,但Modin可以通过缩放pandas来加快工作流程,它在较大的数据集上工作得特别好,因为在这些数据集上,pandas会变得非常缓慢或内存占用过大导致OOM。

!pip install modin[all]
 
 import modin.pandas as pd
 df = pd.read_csv("my_dataset.csv")

以下是modin官网的架构图,有兴趣的研究把:

Pandas:十种数据处理技巧,让你事半功倍

8、extract()

如果经常遇到复杂的半结构化的数据,并且需要从中分离出单独的列,那么可以使用这个方法:

import pandas as pd
 
 regex = (r'(?P[A-Za-z's]+),'
r'(?P<author>[A-Za-zs']+),'
r'(?P<isbn>[d-]+),'
r'(?P<year>d{4}),'
r'(?P<publisher>.+)')
 addr = pd.Series([
 "The Lost City of Amara,Olivia Garcia,978-1-234567-89-0,2023,HarperCollins",
 "The Alchemist's Daughter,Maxwell Greene,978-0-987654-32-1,2022,Penguin Random House",
 "The Last Voyage of the HMS Endeavour,Jessica Kim,978-5-432109-87-6,2021,Simon & Schuster",
 "The Ghosts of Summer House,Isabella Lee,978-3-456789-12-3,2000,Macmillan Publishers",
 "The Secret of the Blackthorn Manor,Emma Chen,978-9-876543-21-0,2023,Random House Children's Books"
])
 addr.str.extract(regex)</pre><p ><p ><img src="/uploads/20230427/168257617390983.png" alt="Pandas:十种数据处理技巧,让你事半功倍" /></p></p><h4  >9、读写剪贴板</h4><p >这个技巧有人一次也用不到,但是有人可能就是需要,比如:在分析中包含PDF文件中的表格时。通常的方法是复制数据,粘贴到Excel中,导出到csv文件中,然后导入Pandas。但是,这里有一个更简单的解决方案:pd.read_clipboard()。我们所需要做的就是复制所需的数据并执行一个方法。</p><p >有读就可以写,所以还可以使用to_clipboard()方法导出到剪贴板。</p><p >但是要记住,这里的剪贴板是你运行python/jupyter主机的剪切板,并不可能跨主机粘贴,一定不要搞混了。</p><h4  >10、数组列分成多列</h4><p >假设我们有这样一个数据集,这是一个相当典型的情况:</p><pre class="brush:javascript;toolbar:false;">import pandas as pd
 df = pd.DataFrame({"a": [1, 2, 3],
"b": [4, 5, 6],
"category": [["foo", "bar"], ["foo"], ["qux"]]})
 
 # let's increase the number of rows in a dataframe
 df = pd.concat([df]*10000, ignore_index=True)</pre><p ><p ><img src="/uploads/20230427/168257617378759.png" alt="Pandas:十种数据处理技巧,让你事半功倍" /></p></p><p >我们想将category分成多列显示,例如下面的</p><p ><p ><img src="/uploads/20230427/168257617465287.png" alt="Pandas:十种数据处理技巧,让你事半功倍" /></p></p><p >先看看最慢的apply:</p><pre class="brush:javascript;toolbar:false;">def dummies_series_apply(df):
return df.join(df['category'].apply(pd.Series) 
.stack() 
.str.get_dummies() 
.groupby(level=0) 
.sum()) 
.drop("category", axis=1)
 %timeit dummies_series_apply(df.copy())
 #5.96 s ± 66.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)</pre><p >sklearn的MultiLabelBinarizer</p><pre class="brush:javascript;toolbar:false;">from sklearn.preprocessing import MultiLabelBinarizer
 def sklearn_mlb(df):
mlb = MultiLabelBinarizer()
return df.join(pd.DataFrame(mlb.fit_transform(df['category']), columns=mlb.classes_)) 
.drop("category", axis=1)
 %timeit sklearn_mlb(df.copy())
 #35.1 ms ± 1.31 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)</pre><p >是不是快了很多,我们还可以使用一般的向量化操作对其求和:</p><pre class="brush:plain;toolbar:false;">def dummies_vectorized(df):
return pd.get_dummies(df.explode("category"), prefix="cat") 
.groupby(["a", "b"]) 
.sum() 
.reset_index()
 %timeit dummies_vectorized(df.copy())
 #29.3 ms ± 1.22 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)</pre><p ><p ><img src="/uploads/20230427/168257617419157.png" alt="Pandas:十种数据处理技巧,让你事半功倍" /></p></p><p >使用第一个方法(在StackOverflow上的回答中非常常见)会给出一个非常慢的结果。而其他两个优化的方法的时间是非常快速的。</p><h4  >总结</h4><p >我希望每个人都能从这些技巧中学到一些新的东西。重要的是要记住尽可能使用向量化操作而不是apply()。此外,除了csv之外,还有其他有趣的存储数据集的方法。不要忘记使用分类数据类型,它可以节省大量内存。感谢阅读!</p>                         </div>
                                                <span class="article_notice">本文内容来源于互联网,如有侵权请联系删除。</span>
                                                <div class="article_otherarticle">
                            <span>作者最新文章</span>
                            <div>
                                                                <div class="otherarticles">
                                    <a href="/news/768041"
                                        title="网易2026年Q2财报:营收301亿元,游戏收入增10%,三款重点新游披露进展"><span>网易2026年Q2财报:营收301亿元,游戏收入增10%,三款重点新游披露进展</span></a>
                                    <span>2026-09-08 17:51</span>
                                </div>
                                                                <div class="otherarticles">
                                    <a href="/news/767757"
                                        title="PDF怎么添加页码?页码位置和起始页怎么设置?"><span>PDF怎么添加页码?页码位置和起始页怎么设置?</span></a>
                                    <span>2026-09-03 09:11</span>
                                </div>
                                                                <div class="otherarticles">
                                    <a href="/news/767732"
                                        title="图片文件怎么转换成PDF?多张图片如何按顺序合成?"><span>图片文件怎么转换成PDF?多张图片如何按顺序合成?</span></a>
                                    <span>2026-09-02 19:33</span>
                                </div>
                                                                <div class="otherarticles">
                                    <a href="/news/767694"
                                        title="CorelDRAW绘制正弦曲线的两种方法:贝塞尔工具与变形工具"><span>CorelDRAW绘制正弦曲线的两种方法:贝塞尔工具与变形工具</span></a>
                                    <span>2026-09-02 16:08</span>
                                </div>
                                                                <div class="otherarticles">
                                    <a href="/news/767658"
                                        title="Excel工作表制作教程:设计易填写、易统计的业务表"><span>Excel工作表制作教程:设计易填写、易统计的业务表</span></a>
                                    <span>2026-09-02 12:11</span>
                                </div>
                                                            </div>
                        </div>
                                                <div class="article_card_class">
                                                        <a href="/newslist/313_1" title="编程开发">编程开发</a>
                            
                        </div>
                                                <div class="article_nearby">
                            <div>
                                <span>上一篇:</span>
                                                                <a href="/news/16516" title="如何使用Java实现基于资金流向的交易策略?" class="woh">如何使用Java实现基于资金流向的交易策略?</a>
                                                            </div>
                            <div>
                                <span>下一篇:</span>
                                                                <a href="/news/768072" title="Photoshop快捷键技巧教程 常用命令一览表及图解" class="woh">Photoshop快捷键技巧教程 常用命令一览表及图解</a>
                                                            </div>
                        </div>
                        <div class="article_related">
                            <div class="index_title flexBox">
                                <span>相关文章</span>
                                <a href="/newslist/1" title="更多">更多</a>
                            </div>
                            <div class="article_listLMs">
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736200" title="using namespace 使用中遇到的问题怎么解决"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605885655125.webp" src="/static/images/moren.png"
                                            alt="using namespace 使用中遇到的问题怎么解决" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736200" title="using namespace 使用中遇到的问题怎么解决"
                                            class="index_article_title woh">using namespace 使用中遇到的问题怎么解决</a>
                                        <p class="woh">命名空间的基本概念与常见引入问题在C++等编程语言中,命名空间(namespace)是一种将代码标识符(如变量、函数、类名)封装在特定名称下的机制,其主要目的是避免命名冲突,尤其是在大型项目或使用多个第三方库时。使用“using namespace”指令可以将指定命名空间中的所有名称引入当前作用域,</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">1</span>
                                                                                                <span class="index_article_author">SunnyJourney</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736199" title="c语言函数递归 实操经验总结:这些技巧很实用"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605879214771.webp" src="/static/images/moren.png"
                                            alt="c语言函数递归 实操经验总结:这些技巧很实用" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736199" title="c语言函数递归 实操经验总结:这些技巧很实用"
                                            class="index_article_title woh">c语言函数递归 实操经验总结:这些技巧很实用</a>
                                        <p class="woh">理解递归的基本原理在C语言中,递归是一种函数调用自身的编程技术。要掌握它,首先需要理解其核心思想:将一个复杂的大问题,分解为一个或几个与原问题相似但规模更小的子问题,直到子问题足够简单,可以直接求解。这个过程通常包含两个关键部分:递归出口和递归体。递归出口定义了问题何时不再继续分解,即最简单、可直接</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">SoftHope</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736198" title="c语言函数递归 怎么选?常见方案对比分析"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605874187563.webp" src="/static/images/moren.png"
                                            alt="c语言函数递归 怎么选?常见方案对比分析" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736198" title="c语言函数递归 怎么选?常见方案对比分析"
                                            class="index_article_title woh">c语言函数递归 怎么选?常见方案对比分析</a>
                                        <p class="woh">递归函数的基本概念与适用场景在C语言编程中,递归是一种函数调用自身的编程技巧。它并非适用于所有问题,但在处理某些具有自相似结构的问题时,能提供极其清晰和优雅的解决方案。递归的核心思想是将一个大规模问题分解为一个或多个同类型但规模更小的子问题,直到子问题简单到可以直接求解。典型的适用场景包括树形结构的</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">归人云淡风轻</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736197" title="Objective-C 内存管理入门:从 alloc 到 dealloc 的生命周期详解"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605862499192.webp" src="/static/images/moren.png"
                                            alt="Objective-C 内存管理入门:从 alloc 到 dealloc 的生命周期详解" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736197" title="Objective-C 内存管理入门:从 alloc 到 dealloc 的生命周期详解"
                                            class="index_article_title woh">Objective-C 内存管理入门:从 alloc 到 dealloc 的生命周期详解</a>
                                        <p class="woh">理解内存管理的基石在Objective-C的编程世界中,内存管理是开发者必须掌握的核心技能之一。它直接关系到应用的性能、稳定性与资源利用效率。与一些采用自动垃圾回收机制的语言不同,Objective-C在很长一段时间里,依赖一套基于引用计数的、需要开发者部分介入的管理规则。这套规则的核心思想是明确的</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">SunnyJourney</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736196" title="如何正确使用 dealloc 以避免 iOS 应用中的内存泄漏"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605861766536.webp" src="/static/images/moren.png"
                                            alt="如何正确使用 dealloc 以避免 iOS 应用中的内存泄漏" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736196" title="如何正确使用 dealloc 以避免 iOS 应用中的内存泄漏"
                                            class="index_article_title woh">如何正确使用 dealloc 以避免 iOS 应用中的内存泄漏</a>
                                        <p class="woh">理解 dealloc 的角色与时机在 iOS 应用开发中,内存管理是保障应用性能与稳定性的基石。dealloc 方法是 Objective-C 中对象生命周期结束时的关键回调,它标志着对象即将被系统回收内存。正确理解其触发时机至关重要:当一个对象的引用计数降为零时,运行时系统会自动调用该对象的 de</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">WarmHope</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736195" title="深入理解 Objective-C 中的 dealloc 方法:内存管理核心机制"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605861197821.webp" src="/static/images/moren.png"
                                            alt="深入理解 Objective-C 中的 dealloc 方法:内存管理核心机制" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736195" title="深入理解 Objective-C 中的 dealloc 方法:内存管理核心机制"
                                            class="index_article_title woh">深入理解 Objective-C 中的 dealloc 方法:内存管理核心机制</a>
                                        <p class="woh">内存管理的基石在Objective-C的世界里,内存管理是开发者必须掌握的核心技能之一。作为一门在手动引用计数(MRC)时代诞生的语言,Objective-C要求程序员对对象的生命周期有清晰的认识。dealloc方法正是这一生命周期中至关重要的终点站。它是一个实例方法,当对象的引用计数降为零时,系统</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">归人云淡风轻</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736194" title="理解 native2ascii:Java 国际化开发中的字符编码工具"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605849623470.webp" src="/static/images/moren.png"
                                            alt="理解 native2ascii:Java 国际化开发中的字符编码工具" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736194" title="理解 native2ascii:Java 国际化开发中的字符编码工具"
                                            class="index_article_title woh">理解 native2ascii:Java 国际化开发中的字符编码工具</a>
                                        <p class="woh">native2ascii 工具的基本定位在Ja va应用程序的国际化与本地化开发过程中,处理非拉丁字符集是一个常见且关键的环节。Ja va内部使用Unicode字符集来统一表示全球各种语言的文字,但其属性文件(.properties)在历史上要求使用ASCII编码,或者更准确地说,要求非ASCII字</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">小确幸</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736193" title="如何使用 native2ascii 转换中文字符为 Unicode 转义序列"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605844216359.webp" src="/static/images/moren.png"
                                            alt="如何使用 native2ascii 转换中文字符为 Unicode 转义序列" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736193" title="如何使用 native2ascii 转换中文字符为 Unicode 转义序列"
                                            class="index_article_title woh">如何使用 native2ascii 转换中文字符为 Unicode 转义序列</a>
                                        <p class="woh">理解 native2ascii 工具的基本用途在软件开发,特别是涉及国际化处理的场景中,开发者常常需要处理不同编码的文本资源。native2ascii 是 Ja va 开发工具包(JDK)中提供的一个命令行实用程序,其主要功能是将包含本地字符编码(非ASCII字符)的文件,转换为包含 Unicode</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">慢热型</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736192" title="Java native2ascii 命令详解:解决属性文件乱码问题"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605843692096.webp" src="/static/images/moren.png"
                                            alt="Java native2ascii 命令详解:解决属性文件乱码问题" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736192" title="Java native2ascii 命令详解:解决属性文件乱码问题"
                                            class="index_article_title woh">Java native2ascii 命令详解:解决属性文件乱码问题</a>
                                        <p class="woh">native2ascii 命令的由来与作用在Ja va开发中,处理国际化资源文件是一个常见需求。资源文件通常以.properties格式存储,用于支持多语言界面。然而,Ja va属性文件默认采用ISO-8859-1字符集编码,这导致了一个直接的问题:当文件中包含非拉丁字符(如中文、日文、韩文等)时,</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">SoftHope</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                                <div class="index_article flexBox">
                                    <a href="http://www.zhengruan.com/news/736191" title="一个 memwatch 实战案例:定位野指针问题"
                                        class="index_article_img"><img data-lazy-img loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="http://www.zhengruan.com/uploads/20260807/178605837119093.webp" src="/static/images/moren.png"
                                            alt="一个 memwatch 实战案例:定位野指针问题" class="oimg" /></a>
                                    <div>
                                        <a href="http://www.zhengruan.com/news/736191" title="一个 memwatch 实战案例:定位野指针问题"
                                            class="index_article_title woh">一个 memwatch 实战案例:定位野指针问题</a>
                                        <p class="woh">内存监控工具的价值与挑战在软件开发,尤其是使用C/C++这类手动管理内存的语言时,内存错误是程序员最常遭遇的难题之一。其中,野指针问题因其隐蔽性和破坏性,往往成为最难定位的“幽灵”缺陷。它可能潜伏在代码中,在特定条件下才被触发,导致程序崩溃、数据损坏或难以预测的行为。传统的调试手段,如打印日志或使用</p>
                                        <div class="index_article_info">
                                            <div class="index_article_infos">
                                                <span
                                                    class="index_article_time">2026-08-07</span>
                                                <span class="index_article_times">0</span>
                                                                                                <span class="index_article_author">RainLight</span>
                                                                                            </div>
                                                                                        <div class="index_article_class">
                                                                                                <a href="http://m.zhengruan.com/newslist/313_1" title="编程开发">编程开发</a>
                                                                                            </div>
                                                                                    </div>
                                    </div>
                                </div>
                                                            </div>
                            <a href="/newslist/313_1" title="查看更多"
                                class="index_more">查看更多</a>
                        </div>
                    </div>
                    <div class="article_listR">
                        <div class="indexMain4R1">
                            <div class="index_title flexBox">
                                <span>热门文章</span>
                                <a href="/newslist/1" title="更多">更多</a>
                            </div>
                            <div class="indexMain4R1M">
                                                                <a href="/news/561233" title="Yandex中文入口及登录使用全攻略" class=""><span
                                        class="woh">Yandex中文入口及登录使用全攻略</span></a>
                                                                <a href="/news/469906" title="B站免费入口永久有效网址推荐" class=""><span
                                        class="woh">B站免费入口永久有效网址推荐</span></a>
                                                                <a href="/news/561969" title="51漫画高清入口及最新章节更新" class=""><span
                                        class="woh">51漫画高清入口及最新章节更新</span></a>
                                                                <a href="/news/559231" title="高德地图开启海拔显示方法" class=""><span
                                        class="woh">高德地图开启海拔显示方法</span></a>
                                                                <a href="/news/527075" title="我的世界网页版即点即玩入口推荐" class=""><span
                                        class="woh">我的世界网页版即点即玩入口推荐</span></a>
                                                                <a href="/news/768058" title="JS金额计算怎么避免四舍五入误差" class=""><span
                                        class="woh">JS金额计算怎么避免四舍五入误差</span></a>
                                                                <a href="/news/768064" title="photoshop智能对象怎么编辑" class=""><span
                                        class="woh">photoshop智能对象怎么编辑</span></a>
                                                                <a href="/news/563134" title="B站免费入口网站高效连接方法" class=""><span
                                        class="woh">B站免费入口网站高效连接方法</span></a>
                                                                <a href="/news/522264" title="QQ网页版登录入口大全 QQ网页版官方登录指南" class=""><span
                                        class="woh">QQ网页版登录入口大全 QQ网页版官方登录指南</span></a>
                                                                <a href="/news/546673" title="学习通网页登录入口及账号使用教程" class=""><span
                                        class="woh">学习通网页登录入口及账号使用教程</span></a>
                                
                            </div>
                        </div>
                        <div class="indexMain4R2">
                            <div class="index_title flexBox">
                                <span>精品专题</span>
                                <a href="/newslist/tag_1" title="更多">更多</a>
                            </div>
                            <div class="indexMain4R2M">
                                                                <div class="indexMain4R2Ms">
                                    <a href="/newslist/141356_1" title="装机必备"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="/uploads/20260916/23a0ca69dd790f4a338bf469823181a8.webp" src="/static/images/moren.png"
                                            alt="装机必备" class="oimg" /></a>
                                    <div>
                                        <a href="/newslist/141356_1" title="装机必备"
                                            class="woh">装机必备</a>
                                        <p class="poh">正软商城装机必备专区,精选办公、浏览器、安全防护、影音播放、压缩解压、设计创作和系统工具等电脑常用正版软件,帮助用户快速完成新电脑软件配置。</p>
                                    </div>
                                </div>
                                                                <div class="indexMain4R2Ms">
                                    <a href="/newslist/2909_1" title="Windows"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="/uploads/20260916/7a276fc2f6c50e3d02985b5c5b8c3791.webp" src="/static/images/moren.png"
                                            alt="Windows" class="oimg" /></a>
                                    <div>
                                        <a href="/newslist/2909_1" title="Windows"
                                            class="woh">Windows</a>
                                        <p class="poh">正软商城Windows软件专区,汇集适用于Windows电脑的办公、设计、安全防护、影音播放、开发工具和系统优化软件,提供软件介绍、系统要求、正版授权及购买下载服务。</p>
                                    </div>
                                </div>
                                                                <div class="indexMain4R2Ms">
                                    <a href="/newslist/3169_1" title="macOS软件"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='/static/images/moren.png'"
                                            data-src="/uploads/20260916/67558ffa810c3aac92a7fc0ec0379666.png" src="/static/images/moren.png"
                                            alt="macOS软件" class="oimg" /></a>
                                    <div>
                                        <a href="/newslist/3169_1" title="macOS软件"
                                            class="woh">macOS软件</a>
                                        <p class="poh">正软商城macOS软件专区,精选适用于Mac电脑的办公、设计、影音、效率、开发和系统工具,提供软件功能介绍、macOS兼容版本、正版授权及购买下载服务。</p>
                                    </div>
                                </div>
                                                            </div>
                        </div>
                        <div class="right_list1">
                            <div class="index_title flexBox">
                                <span>Mac软件</span>
                                <a href="/newslist/3169_1" title="更多">更多</a>
                            </div>
                            <div class="right_list1M">
                                                                <div class="right_list1s">
                                    <a href="/news/752345" title="灵活计算器"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='./static/images/moren.png'"
                                            data-src="/uploads/20260817/178697900269097.png" src="/static/images/moren.png"
                                            alt="灵活计算器" class="oimg" /></a>
                                    <div>
                                        <a href="/news/752345" title="灵活计算器"
                                            class="right_list1s_title woh">灵活计算器</a>
                                        <div>
                                                                                        <span>macOS/iOS/Android</span>

                                                                                    </div>
                                        <p class="woh">灵活计算器是一款笔记式算数应用,支持实时计算、动态关联和云端同步功能。记录、整理和输出之间的过渡会更自然,适合长期写作、做笔记或持续沉淀个人内容。</p>
                                    </div>
                                </div>
                                                                <div class="right_list1s">
                                    <a href="/news/752357" title="赤友清理大师"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='./static/images/moren.png'"
                                            data-src="/uploads/20260817/178697957425469.png" src="/static/images/moren.png"
                                            alt="赤友清理大师" class="oimg" /></a>
                                    <div>
                                        <a href="/news/752357" title="赤友清理大师"
                                            class="right_list1s_title woh">赤友清理大师</a>
                                        <div>
                                                                                        <span>macOS</span>

                                                                                    </div>
                                        <p class="woh">赤友清理大师是一款为 Mac 设计的智能清理优化工具,可精准扫描垃圾、大文件、重复文件等,释放磁盘空间。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。</p>
                                    </div>
                                </div>
                                                                <div class="right_list1s">
                                    <a href="/news/752368" title="极度公式"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='./static/images/moren.png'"
                                            data-src="/uploads/20260817/178698012420573.png" src="/static/images/moren.png"
                                            alt="极度公式" class="oimg" /></a>
                                    <div>
                                        <a href="/news/752368" title="极度公式"
                                            class="right_list1s_title woh">极度公式</a>
                                        <div>
                                                                                        <span>Windows/macOS/Linux</span>

                                                                                    </div>
                                        <p class="woh">极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。</p>
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                        <div class="right_list1">
                            <div class="index_title flexBox">
                                <span>WINDOWS</span>
                                <a href="/newslist/2909_1" title="更多">更多</a>
                            </div>
                            <div class="right_list1M">
                                                                <div class="right_list1s">
                                    <a href="/news/752356" title="Windows 10"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='./static/images/moren.png'"
                                            data-src="/uploads/20260817/178697951292792.png" src="/static/images/moren.png"
                                            alt="Windows 10" class="oimg" /></a>
                                    <div>
                                        <a href="/news/752356" title="Windows 10"
                                            class="right_list1s_title woh">Windows 10</a>
                                        <div>
                                                                                        <span>Windows</span>

                                                                                    </div>
                                        <p class="woh">Windows 10 是一款微软推出的经典操作系统,拥有硬件兼容性与多任务处理能力。它更偏向把系统状态查看和常用调节动作放在一起,适合需要持续观察和微调设备状态的场景。</p>
                                    </div>
                                </div>
                                                                <div class="right_list1s">
                                    <a href="/news/752368" title="极度公式"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='./static/images/moren.png'"
                                            data-src="/uploads/20260817/178698012420573.png" src="/static/images/moren.png"
                                            alt="极度公式" class="oimg" /></a>
                                    <div>
                                        <a href="/news/752368" title="极度公式"
                                            class="right_list1s_title woh">极度公式</a>
                                        <div>
                                                                                        <span>Windows/macOS/Linux</span>

                                                                                    </div>
                                        <p class="woh">极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。</p>
                                    </div>
                                </div>
                                                                <div class="right_list1s">
                                    <a href="/news/752369" title="密码键盘"><img data-lazy-img
                                            loading="lazy" decoding="async"
                                            onerror="this.onerror=null;this.src='./static/images/moren.png'"
                                            data-src="/uploads/20260818/dfc07fc7a04bdc39bd5410c9bcf26de8.png" src="/static/images/moren.png"
                                            alt="密码键盘" class="oimg" /></a>
                                    <div>
                                        <a href="/news/752369" title="密码键盘"
                                            class="right_list1s_title woh">密码键盘</a>
                                        <div>
                                                                                        <span>Windows/macOS/iOS/Android</span>

                                                                                    </div>
                                        <p class="woh">密码键盘是一款兼具安全性与便捷性的高效密码管理器。日常使用里的持续防护和信息管理会更突出,适合把安全控制放进长期使用流程中的场景。</p>
                                    </div>
                                </div>
                                                            </div>
                        </div>

                                            </div>
                </div>
            </div>
        </main>
                <footer>
        <div class="footer2">
        <p>网站备案号:苏ICP备2026018738号-1 联系邮箱:bd@zhengruan.com <a href="/sitemap.xml">网站地图</a></p>
        <p>Copyright ©2018-2026</p>
    </div>
</footer>

<!--底部 end-->
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?3835539565b311d85319cd21da8fd0d9";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
<!-- Matomo -->
<script>
    var _paq = window._paq = window._paq || [];
    /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function () {
        var u = "https://tongji.php.cn/";
        _paq.push(['setTrackerUrl', u + 'matomo.php']);
        _paq.push(['setSiteId', '36']);
        var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
        g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s);
    })();
</script>
<!-- End Matomo Code -->
    </body>
    <script src="/static/layui/layui.all.js"></script>
<script src="/static/swiper/swiper-bundle.min.js"></script>
<script src="/static/js/common.js"></script>

    <script>
        let redirectUrl = '';

        function showConfirmModal(url) {
            redirectUrl = url;
            document.querySelector('.goto_url').textContent = redirectUrl;
            document.getElementById('confirmModal').style.display = 'flex';
        }

        function hideConfirmModal() {
            document.getElementById('confirmModal').style.display = 'none';
        }

        function confirmRedirect() {
            if (redirectUrl) {
                window.open(redirectUrl, '_blank');
            }
            hideConfirmModal();
        }
        document.getElementById('confirmModal').addEventListener('click', function (e) {
            if (e.target === this) {
                hideConfirmModal();
            }
        });
    </script>

</html>