我只知道describe()
函數。是否還有其他類似於str()
,summary()
和head()
的功能?什麼是類似於str(),summary()和head()等R函數的Python熊貓類?
16
A
回答
5
summary()
〜describe()
head()
〜head()
我不知道有關str()
當量。
+1
dtypes()是str()的一個粗略等價物() –
1
我不知道很多關於R,但這裏有一些線索:
str =>
困難的一年......對於功能,你可以在數據集使用DIR(),DIR()會給你所有的方法,所以也許這不是你想要的...
summary => describe.
查看參數來自定義結果。
head => your can use head(), or use slices.
正如你已經做的那樣。要獲取數據集的前10行ds ds[:10]
同樣用於尾部ds[:-10]
15
這提供了與R的str()
類似的輸出。它呈現獨特的值而不是初始值。
def rstr(df): return df.shape, df.apply(lambda x: [x.unique()])
print(rstr(iris))
((150, 5), sepal_length [[5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.4, 4.8, 4.3,...
sepal_width [[3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 2.9, 3.7,...
petal_length [[1.4, 1.3, 1.5, 1.7, 1.6, 1.1, 1.2, 1.0, 1.9,...
petal_width [[0.2, 0.4, 0.3, 0.1, 0.5, 0.6, 1.4, 1.5, 1.3,...
class [[Iris-setosa, Iris-versicolor, Iris-virginica]]
dtype: object)
5
熊貓提供廣泛Comparison with R/R libraries:
R | Pandas
---------------------------
summary(df) | df.describe()
head(df) | df.head()
4
對於Python相當於R中的str()
功能的,我使用的方法dtypes
。這將爲每列提供數據類型。
In [22]: df2.dtypes
Out[22]:
Survived int64
Pclass int64
Sex object
Age float64
SibSp int64
Parch int64
Ticket object
Fare float64
Cabin object
Embarked object
dtype: object
19
在大熊貓info()
方法創建一個非常類似的輸出如R的str()
:
> str(train)
'data.frame': 891 obs. of 13 variables:
$ PassengerId: int 1 2 3 4 5 6 7 8 9 10 ...
$ Survived : int 0 1 1 1 0 0 0 0 1 1 ...
$ Pclass : int 3 1 3 1 3 3 1 3 3 2 ...
$ Name : Factor w/ 891 levels "Abbing, Mr. Anthony",..: 109 191 358 277 16 559 520 629 417 581 ...
$ Sex : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ...
$ Age : num 22 38 26 35 35 NA 54 2 27 14 ...
$ SibSp : int 1 1 0 1 0 0 0 3 0 1 ...
$ Parch : int 0 0 0 0 0 0 0 1 2 0 ...
$ Ticket : Factor w/ 681 levels "110152","110413",..: 524 597 670 50 473 276 86 396 345 133 ...
$ Fare : num 7.25 71.28 7.92 53.1 8.05 ...
$ Cabin : Factor w/ 148 levels "","A10","A14",..: 1 83 1 57 1 1 131 1 1 1 ...
$ Embarked : Factor w/ 4 levels "","C","Q","S": 4 2 4 4 4 3 4 4 4 2 ...
$ Child : num 0 0 0 0 0 NA 0 1 0 1 ...
train.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 891 entries, 0 to 890
Data columns (total 12 columns):
PassengerId 891 non-null int64
Survived 891 non-null int64
Pclass 891 non-null int64
Name 891 non-null object
Sex 891 non-null object
Age 714 non-null float64
SibSp 891 non-null int64
Parch 891 non-null int64
Ticket 891 non-null object
Fare 891 non-null float64
Cabin 204 non-null object
Embarked 889 non-null object
dtypes: float64(2), int64(5), object(5)
memory usage: 83.6+ KB
+0
str是不是告訴非空元素的個數,誤了? – hhh
相關問題
- 1. 尋找一個類似於DataFrame.nafill()的熊貓函數
- 2. 轉換類:str json到python中的熊貓數據框
- 3. 什麼是R的qnorm的熊貓等價物()
- 4. 熊貓:擴展數據幀逐行,類似的r SurvSplit()
- 5. 爲什麼不是類型(字符串)等於「<class 'str'>」?
- 6. Python熊貓平等地R groupby變異
- 7. Python熊貓:等同於SQL的聚合函數?
- 8. 什麼是Perl的等效Python的類型()函數
- 9. 另一個類似於is()的JQuery函數是什麼?
- 10. 什麼是類似於MySQL FIELD()函數的MS SQL Server功能?
- 11. 什麼是可能的熊貓基本/標量數據類型?
- 12. Python的熊貓由函數
- 13. 在熊貓中,函數「all」中是否有等價的python?
- 14. 在Python中,R的「phyper」函數等價於什麼?
- 15. python`str()`函數是否調用類的__str __()`函數?
- 16. BeautifulSoup:類似。頭(東西)函數在熊貓
- 17. 的Python - Unorderable類型:STR()<int()函數
- 18. 什麼是類型和什麼是類型構造函數scala
- 19. 功能類似於Matlab中的head()
- 20. 類似於R中
- 21. 熊貓:什麼是相當於SQL組?
- 22. 什麼是類似於Rails ActionController類中找到的around_filter的C#等價物?
- 23. 什麼是Python函數scipy.sparse.bmat的R等價物?
- 24. 是否有類似於Python計數器功能的Javascript函數?
- 25. 熊貓:str類型的列轉換爲tslib.Timestamp後使用應用函數
- 26. Python的等價物R的熊貓數據框列表
- 27. strftime函數熊貓 - Python
- 28. Python的等價於R的logspace_add函數?
- 29. 對於Web2py(Python)而言,最類似的Web框架是什麼?
- 30. 不同類型的熊貓和python中的日期類型
可能是這個鏈接可以幫助http://pandas.pydata.org/pandas-docs/stable/basics。 html – akrun