파이썬은 높은 수준의 프로그래밍 및 낮은 수준입니다 나를 위해 그것의 가능한 사용 NumPy와/팬더 ...
는 C++의 경우 ... 그래서에있는 NumPy와 팬더 또는 다른 libs와 ..
는()`python3 또는`dict.itervalues ()`python2에에 ...
>>> import numpy as np, pandas as pd
>>> p1 = np.arange(10)
>>> dct = dict(
... p1 = np.arange(10),
... p2 = np.ones(10),
... p3 = np.zeros(10),
... p33 = np.ones(10)*10,
... p4 = np.linspace(0,1,10))
>>>
>>> dct
{'p2': array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]), 'p33': array([ 10., 10., 10., 10., 10.,
10., 10., 10., 10., 10.]), 'p1': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), 'p4': array([ 0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444,
0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ]), 'p3': array([ 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0.])}
>>> from pprint import pprint as pr
>>> pr(dct)
{'p1': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
'p2': array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]),
'p3': array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]),
'p33': array([ 10., 10., 10., 10., 10., 10., 10., 10., 10., 10.]),
'p4': array([ 0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444,
0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ])}
>>> df = pd.DataFrame(dct)
>>> df
p1 p2 p3 p33 p4
0 0 1.0 0.0 10.0 0.000000
1 1 1.0 0.0 10.0 0.111111
2 2 1.0 0.0 10.0 0.222222
3 3 1.0 0.0 10.0 0.333333
4 4 1.0 0.0 10.0 0.444444
5 5 1.0 0.0 10.0 0.555556
6 6 1.0 0.0 10.0 0.666667
7 7 1.0 0.0 10.0 0.777778
8 8 1.0 0.0 10.0 0.888889
9 9 1.0 0.0 10.0 1.000000
>>> df.T
0 1 2 3 4 5 6 \
p1 0.0 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000
p2 1.0 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
p3 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
p33 10.0 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000
p4 0.0 0.111111 0.222222 0.333333 0.444444 0.555556 0.666667
7 8 9
p1 7.000000 8.000000 9.0
p2 1.000000 1.000000 1.0
p3 0.000000 0.000000 0.0
p33 10.000000 10.000000 10.0
p4 0.777778 0.888889 1.0
>>> df = df.T
>>> df.columns = ['x%d'%(n+1) for n in df.columns.values]
>>> df
x1 x2 x3 x4 x5 x6 x7 \
p1 0.0 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000
p2 1.0 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
p3 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
p33 10.0 10.000000 10.000000 10.000000 10.000000 10.000000 10.000000
p4 0.0 0.111111 0.222222 0.333333 0.444444 0.555556 0.666667
x8 x9 x10
p1 7.000000 8.000000 9.0
p2 1.000000 1.000000 1.0
p3 0.000000 0.000000 0.0
p33 10.000000 10.000000 10.0
p4 0.777778 0.888889 1.0
>>> df.x3
p1 2.000000
p2 1.000000
p3 0.000000
p33 10.000000
p4 0.222222
Name: x3, dtype: float64
>>> df.x3 == 0
p1 False
p2 False
p3 True
p33 False
p4 False
Name: x3, dtype: bool
>>> np.sum(df.x3 == 0)
1
>>>
'dict.values 그것을 확인하십시오. –
iteritems()를 사용 했습니까? –
어쨌든'it = iter (dict.iteritems())' '''범위 (0, len (dict))에있는 항목 : \t data = it.next() [1]'''무엇입니까 나는 시도하고 여전히 천천히, 키 이름에 의한 조회만큼 느리다. –