永发信息网

python pandas怎么用

答案:1  悬赏:70  手机版
解决时间 2021-11-29 21:59
  • 提问者网友:眉目添风霜
  • 2021-11-29 05:14
python pandas怎么用
最佳答案
  • 五星知识达人网友:大漠
  • 2021-11-29 06:09
本篇博文主要介绍数据分析包pandas的使用,主要参考资料来自pandas官网,掌握以下内容可以帮助data scientist快速理解pandas日常的数据分析操作,读者可以自己定义一些数据,跟着练习一下,pandas确实挺强大的,比自己一点点的去写numpy要省事许多,可以为大家省下不少时间精力将工作重点放在算法或者业务的深入理解方面,内容so young so naive,但是仔细读来也可以have some fun!
In [4]:
import pandas as pdimport numpy as npimport matplotlib.pyplot as plt

In [5]:
s=pd.Series([1,3,5,np.nan,6,8]) #产生一个序列

In [6]:
s

Out[6]:
0 1
1 3
2 5
3 NaN
4 6
5 8
dtype: float64

In [7]:
dates=pd.date_range('20160501',periods=6)

In [8]:
dates

Out[8]:

[2016-05-01, ..., 2016-05-06]
Length: 6, Freq: D, Timezone: None

In [10]:
df=pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))

In [11]:
df

Out[11]:

A
B
C
D

2016-05-01
0.695733 0.070252 0.131565 -0.897799

2016-05-02
-0.279032 1.430353 0.246015 1.247282

2016-05-03
-0.727831 -0.422250 0.435165 0.089780

2016-05-04
-0.899446 -0.372851 0.811766 -1.071206

2016-05-05
-1.250048 -0.019416 1.248958 -0.900567

2016-05-06
0.605871 -1.975671 0.202865 -1.491969

In [12]:
df2=pd.DataFrame({'A':1,
'B':pd.Timestamp('20160501'),
'C':pd.Series(1,index=list(range(4)),dtype='float32'),
'D':np.array([3]*4,dtype='int32'),
'E':pd.Categorical(["test","train","test","train"]),
'F':'foo'})

In [13]:
df2

Out[13]:

A
B
C
D
E
F

0
1 2016-05-01 1 3 test foo

1
1 2016-05-01 1 3 train foo

2
1 2016-05-01 1 3 test foo

3
1 2016-05-01 1 3 train foo

In [14]:
df2.dtypes
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯