擅长:python、mysql、java
<p>除了在创建或使用数据帧时将字符串数据转换为数字的其他解决方案之外,还可以使用<code>xlsxwriter</code>引擎的选项来完成此任务:</p>
<pre><code>writer = pd.ExcelWriter('output.xlsx',
engine='xlsxwriter',
options={'strings_to_numbers': True})
</code></pre>
<p>从<a href="https://xlsxwriter.readthedocs.io/workbook.html" rel="noreferrer">docs</a>:</p>
<blockquote>
<p><strong><code>strings_to_numbers</code></strong>: Enable the <code>worksheet.write()</code> method to convert strings to numbers, where possible, using <code>float()</code> in order to avoid an Excel warning about "Numbers Stored as Text".</p>
</blockquote>