您的位置:首页 > 其它

pandas之DataFrame创建

2017-05-01 23:03 477 查看
# -*- coding: utf-8 -*-
"""
Created on Mon May  1 21:18:29 2017

@author: you
"""

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

########################################
#s = pd.Series(data, index=index)
#a Python dict
#an ndarray
#a scalar value (like 5)
########################################

#form ndarray
s0 = pd.Series(np.random.randn(6),index=['A', 'B', 'C','D','E','F'])

print (s0)
print('-----------------------')
print (s0.index)
print('-----------------------')

s1 = pd.Series(np.random.randn(5))
print(s1)

print('-----------------------')
s2 = pd.Series([1, 3, 5, np.nan, 6, 8])
print(s2)

print('-----------------------')
# from dict
d = {'a' : 0., 'b' : 1., 'c' : 2.}
print(pd.Series(d))


A   -0.592624
B   -0.131010
C    1.627316
D   -0.702999
E   -0.247293
F   -0.500999
dtype: float64
-----------------------
Index(['A', 'B', 'C', 'D', 'E', 'F'], dtype='object')
-----------------------
0   -1.147300
1    0.320793
2    1.705771
3    1.066233
4   -1.344791
dtype: float64
-----------------------
0    1.0
1    3.0
2    5.0
3    NaN
4    6.0
5    8.0
dtype: float64
-----------------------
a    0.0
b    1.0
c    2.0
dtype: float64
>>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: