pandas數(shù)據(jù)類型轉(zhuǎn)換 dataframegroupby怎么變?yōu)閐ataframe?
dataframegroupby怎么變?yōu)閐ataframe?使用pandas進行數(shù)據(jù)統(tǒng)計分析時,您可能不知道如何保存groupby函數(shù)的分組結(jié)果。我的解決方案是:通過reset index()函數(shù)可以
dataframegroupby怎么變?yōu)閐ataframe?
使用pandas進行數(shù)據(jù)統(tǒng)計分析時,您可能不知道如何保存groupby函數(shù)的分組結(jié)果。我的解決方案是:通過reset index()函數(shù)可以將groupby()的分組結(jié)果轉(zhuǎn)換成dataframe對象,這樣就可以保存了
如何將list轉(zhuǎn)化為dataframe?
您可以使用列表轉(zhuǎn)換時間格式。
取出相應的列表參數(shù),使用相應的轉(zhuǎn)換,如果沒有,嘗試強類型轉(zhuǎn)換
pandas.dataframe怎么把列變成索引?
在數(shù)據(jù)幀中,根據(jù)一定的條件,得到符合要求的行元素的位置。
代碼如下:
[Python]查看純拷貝
DF=pd.數(shù)據(jù)幀({“BoolCol”:[1,2,3,3,4],“attr”:[22,33,22,44,66]},
index=[10,20,30,40,50])打印(df)
a=df[(df.BoolCol==3)&安培(數(shù)據(jù)框?qū)傩?=22)]. 索引.tolist()
打?。╝)
DF如下所示。上面,通過選擇“boolcol”值為3,“attr”值為22的行,我們可以得到該行在DF中的位置
注意:返回的位置是索引列表,根據(jù)索引的不同而不同。這很容易成為數(shù)組中的默認下標。
[python]查看純拷貝
BoolCol attr
10 1 22
20 2 33
30 3 22
40 3 44
50 4 66
[30]