擅长:python、mysql、java
<p>单括号生成pandas的序列,而双括号生成pandas的数据帧。在</p>
<p>下面是一个例子:</p>
<pre><code>d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
df
col1 col2
0 1 3
1 2 4
</code></pre>
<p>现在让我们同时使用双括号和单括号打印类型。在</p>
<p>单支架产生:</p>
^{pr2}$
<p>双括号表示:</p>
<pre><code>type(df[["col1"]])
pandas.core.frame.DataFrame
</code></pre>
<p>现在你看到了区别,单括号和双括号索引的区别有两个不同的目的。如果要从数据帧中的现有列创建新的数据帧,请使用双括号。在</p>
<p>还有一个类似的答案,还有更多的解释。<a href="https://stackoverflow.com/questions/45201104/the-difference-between-double-brace-and-single-brace-indexing-i?rq=1">The difference between double brace `[[...]]` and single brace `[..]` indexing in Pandas</a></p>