擅长:python、mysql、java
<h2><a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_string.html" rel="nofollow noreferrer">^{<cd1>}</a>/<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.to_string.html" rel="nofollow noreferrer">^{<cd2>}</a></h2>
<p>这些方法具有多种参数,可用于配置打印时显示的信息以及显示方式。默认情况下<code>Series.to_string</code>有<code>name=False</code>和<code>dtype=False</code>,因此我们另外指定<code>index=False</code>:</p>
<pre><code>s = pd.Series(['race', 'gender'], index=[311, 317])
print(s.to_string(index=False))
# race
# gender
</code></pre>
<hr/>
<p>如果索引很重要,则默认值为<code>index=True</code>:</p>
<pre><code>print(s.to_string())
#311 race
#317 gender
</code></pre>
<hr/>
<h2><a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.cat.html" rel="nofollow noreferrer">^{<cd8>}</a></h2>
<p>当您不关心索引,只希望值左对齐时,cat使用<code>'\n'</code>。值必须是字符串,因此如果需要,请首先转换</p>
<pre><code>#s = s.astype(str)
print(s.str.cat(sep='\n'))
#race
#gender
</code></pre>