[英]in python pandas, is there anything like xbar in q?
對於像
x=[1.2 3.1 4.1 5.2 3.1], in q, there is
xbar(x,1)
變成了
[1 3 4 5 3]
python pandas中有這樣的東西嗎? 謝謝!
您在找這個嗎?
import pandas as pd
d = {'one' : pd.Series([1.1, 2.1, 3.1, 4.1]), 'two' : pd.Series([1.1, 2.1, 3.1, 4.1])}
d = pd.DataFrame(d)
d = d.astype(int) # Thanks to @filmor
# Or
d = d.applymap(int)
您可以簡單地map
列表,如下所示:
In [2]: map(int,x)
Out[2]: [1, 3, 4, 5, 3]
或者,如果您使用的是熊貓(如您的問題所示),請使用astype
方法或map
:
In [3]: import pandas as pd
In [4]: x = pd.Series(x)
In [5]: x
Out[5]:
0 1.2
1 3.1
2 4.1
3 5.2
4 3.1
dtype: float64
In [6]: x.astype(int)
Out[6]:
0 1
1 3
2 4
3 5
4 3
dtype: int32
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.