pandas_基础课

import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(5), index=["a","b","c","d","e"])
s
a    0.365672
b   -0.259483
c   -0.404180
d   -0.310866
e   -0.256827
dtype: float64
s.index
Index(['a', 'b', 'c', 'd', 'e'], dtype='object')
s = pd.Series(np.random.randn(5))
s
0   -0.788125
1   -1.291259
2    0.014401
3   -1.244146
4    0.712529
dtype: float64
d = {"a":0, "b":1, "d":3}
s = pd.Series(d, index=list("abcd"))
s
a    0.0
b    1.0
c    NaN
d    3.0
dtype: float64
s = pd.Series(5, index=list("abcd"))
s
a    5
b    5
c    5
d    5
dtype: int64
s = pd.Series(np.random.randn(5))
s
0   -1.065998
1   -0.459723
2   -1.676296
3    0.169716
4   -0.402579
dtype: float64
s[0]
-1.0659982426438701
s[:3]
0   -1.065998
1   -0.459723
2   -1.676296
dtype: float64
s[2:5]
2   -1.676296
3    0.169716
4   -0.402579
dtype: float64
s[[1,3,4]]
1   -0.459723
3    0.169716
4   -0.402579
dtype: float64
np.sin(s)
0   -0.875272
1   -0.443700
2   -0.994440
3    0.168902
4   -0.391792
dtype: float64
s = pd.Series(np.random.randn(5),index=["a","b","c","d","e"])
s
a   -0.013971
b   -0.301559
c    1.540719
d   -0.158722
e    0.504045
dtype: float64
s["a"]
-0.013970643761681575
s["b"]=3
s
a   -0.013971
b    3.000000
c    1.540719
d   -0.158722
e    0.504045
dtype: float64
s["g"]=100
s
a     -0.013971
b      3.000000
c      1.540719
d     -0.158722
e      0.504045
g    100.000000
dtype: float64
print(s.get("f"))
None
s1 = pd.Series(np.random.randn(3), index=["a","c","e"])
s2 = pd.Series(np.random.randn(3), index=["a","d","e"])
print("{0}\n\n{1}".format(s1,s2))
a    0.002169
c    0.799666
e   -0.138819
dtype: float64

a    1.147344
d   -1.013595
e   -1.466308
dtype: float64
s1 + s2
a    1.149512
c         NaN
d         NaN
e   -1.605126
dtype: float64
d = {"one": pd.Series([1,2,3],index=["a","b","c"]),
    "two": pd.Series([1,2,3,4], index=["a","b","c","d"])}
df = pd.DataFrame(d)
df
onetwo
a1.01
b2.02
c3.03
dNaN4
df = pd.DataFrame(d, index=["d","b","a"])
df
onetwo
dNaN4
b2.02
a1.01
df = pd.DataFrame(d, columns=["two","three"])
df
twothree
a1NaN
b2NaN
c3NaN
d4NaN
d = {"one" : [1,2,3,4],
    "two" : [21,22,23,24]}
df = pd.DataFrame(d)
df
onetwo
0121
1222
2323
3424
data = [(1,2.2,"hello"), (2,3,"world")]
df = pd.DataFrame(data,index=["one","two"], columns=list("ABC"))
df
ABC
one12.2hello
two23.0world
data = [{"a":1, "b":2},{"a":5,"b":10,"c":20}]
df = pd.DataFrame(data, index=["A","B"])
df
abc
A12NaN
B51020.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值