擅长:python、mysql、java
<p>在<code>pandas</code>中没有字符串<code>dtype</code>。如<a href="https://pandas.pydata.org/pandas-docs/stable/basics.html#mixed-dtypes" rel="nofollow noreferrer">docs</a>中所述:</p>
<blockquote>
<p>Note When working with heterogeneous data, the dtype of the resulting ndarray will be chosen to accommodate all of the data involved. For example, if strings are involved, the result will be of object dtype. If there are only floats and integers, the resulting array will be of float dtype.</p>
</blockquote>
<p>至于在整个数据帧中用<code>,</code>替换<code>.</code>,请用<code>replace</code>替换<code>regex = True</code>:</p>
<pre><code>df = df.replace(',','.',regex=True)
# or
df.replace(',','.',regex=True, inplace = True)
</code></pre>
<p><strong>例如:</strong>如果您的数据帧<code>df</code>看起来像:</p>
<pre><code>>>> df
col1 col2
0 x,x blah,blah
1 y,z hello,world
2 z.z ,.,.,.
</code></pre>
<p>然后:</p>
<pre><code>df = df.replace(',','.',regex=True)
>>> df
col1 col2
0 x.x blah.blah
1 y.z hello.world
2 z.z ......
</code></pre>