熊猫0.12.0
在下面的DataFrame中,为什么例如它混杂了索引?看看4,索引从1,15,6,7开始.大熊猫用什么来决定如何订购,我会怀疑索引在相同的值上保持顺序.
mydf=pd.DataFrame(np.random.randint(1, 6, 20),columns=["stars"])
mydf.sort(['stars'], ascending=False)
stars
19 5
14 5
1 4
15 4
6 4
7 4
4 3
12 3
18 3
8 2
2 2
9 2
10 2
11 2
13 2
16 2
5 1
3 1
17 1
0 1
Run Code Online (Sandbox Code Playgroud) 我有一个 DataFrame,它有一个空列“pred”,我希望用一些特定值更新它。它们最初位于 numpy 数组中,但我将它们放在一个名为“this”的系列中: print(type(predictions))
print(predictions)
['collection2' 'collection2' 'collection2' 'collection1' 'collection2'
'collection1']
this = pd.Series(predictions, index=test_indices)
print(type(data))
<class 'pandas.core.frame.DataFrame'>
print(data.shape)
(35, 4)
print(data.iloc[test_indices])
class pred text \
223 collection2 [] Fellow-Citizens of the Senate and House of Rep...
20 collection1 [] The period for a new election of a citizen to ...
12 collection1 [] Fellow Citizens of the Senate and of the House...
13 collection1 [] Whereas combinations to defeat the execution o...
212 collection2 [] MR. PRESIDENT AND …Run Code Online (Sandbox Code Playgroud)