美文网首页
python基础-8-数据分析python——pandas——d

python基础-8-数据分析python——pandas——d

作者: 比特跃动 | 来源:发表于2019-03-21 21:34 被阅读0次

1.pandas dataframe初识

索引的区间是左闭右开。

//input1
import pandas as pd
d= {
    'name':['Eren','Elan','Eler'],
    'sex':['male','female','male'],
    'age':[18,19,20]
}
pd.DataFrame(d)

//output1
    name    sex     age
0   Eren    male    18
1   Elan    female  19
2   Eler    male    20




//input2
d['age']

//output2
[18, 19, 20]




//input3
d['age'][1]

//output3
19

数组多维结构

//input
pd.DataFrame([1,2,3,4])

//output
    0
0   1
1   2
2   3
3   4





//input
pd.DataFrame([[1,2,3,4],[4,5,6,7]])

//output
    0   1   2   3
0   1   2   3   4
1   4   5   6   7




//input
pd.DataFrame([[1,2,3,4],[5,6,7,8]],index=list('12'),columns=list('abcd'))

//output
    a   b   c   d
1   1   2   3   4
2   5   6   7   8

2.pandas dataframe进阶

import pandas as pd
d= {
    'name':['Eren','Elan','Eler'],
    'sex':['male','female','male'],
    'age':[18,18,20]
}
pd.DataFrame(d)

//output1
    name    sex age
0   Eren    male    18
1   Elan    female  18
2   Eler    male    20

iloc第几行,loc行标签

//input2
df = pd.DataFrame(d)
df.query('age==18')

//output2
    name    sex     age
0   Eren    male    18
1   Elan    female  18




//input3
df.iloc[0:2]
//output3
    name    sex     age
0   Eren    male    18
1   Elan    female  18



//input4
df.index = list('abc')
df.iloc[0:2]

//output
    name    sex     age
a   Eren    male    18
b   Elan    female  18





//input5
df.loc[['a','b']]

//output5

    name    sex     age
a   Eren    male    18
b   Elan    female  18

相关文章

网友评论

      本文标题:python基础-8-数据分析python——pandas——d

      本文链接:https://www.haomeiwen.com/subject/nndhvqtx.html