import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
s = pd.Series([1, 3, 5, np.nan, 6, 8])
s
0 1.0 1 3.0 2 5.0 3 NaN 4 6.0 5 8.0 dtype: float64
dates = pd.date_range('20130101', periods=6)
dates
DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06'], dtype='datetime64[ns]', freq='D')
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))
df
A | B | C | D | |
---|---|---|---|---|
2013-01-01 | 0.830988 | 0.211301 | -0.926818 | -0.613411 |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -0.396750 |
df2 = pd.DataFrame({
'A': 1.,
'B': pd.Timestamp('20130101'),
'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'
})
df2
A | B | C | D | E | F | |
---|---|---|---|---|---|---|
0 | 1.0 | 2013-01-01 | 1.0 | 3 | test | foo |
1 | 1.0 | 2013-01-01 | 1.0 | 3 | train | foo |
2 | 1.0 | 2013-01-01 | 1.0 | 3 | test | foo |
3 | 1.0 | 2013-01-01 | 1.0 | 3 | train | foo |
df2.dtypes
A float64 B datetime64[ns] C float32 D int32 E category F object dtype: object
df2.E
0 test 1 train 2 test 3 train Name: E, dtype: category Categories (2, object): [test, train]
df.head()
A | B | C | D | |
---|---|---|---|---|
2013-01-01 | 0.830988 | 0.211301 | -0.926818 | -0.613411 |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 |
df.tail(3)
A | B | C | D | |
---|---|---|---|---|
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -0.396750 |
df.index
DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06'], dtype='datetime64[ns]', freq='D')
df.columns
Index([u'A', u'B', u'C', u'D'], dtype='object')
df.values
array([[ 0.83098768, 0.21130117, -0.92681805, -0.61341131], [-1.31499226, 0.53297706, 1.19236594, -1.10684677], [ 0.89064029, -1.03656616, -2.18951045, -0.39705036], [ 1.56529377, -0.90157838, 1.14826665, 0.28758407], [ 0.18088986, 2.3018887 , -0.00307499, 0.47862784], [-0.05043964, -0.84061391, -0.54780954, -0.39674995]])
df.describe()
A | B | C | D | |
---|---|---|---|---|
count | 6.000000 | 6.000000 | 6.000000 | 6.000000 |
mean | 0.350397 | 0.044568 | -0.221097 | -0.291308 |
std | 0.996165 | 1.281361 | 1.296148 | 0.586357 |
min | -1.314992 | -1.036566 | -2.189510 | -1.106847 |
25% | 0.007393 | -0.886337 | -0.832066 | -0.559321 |
50% | 0.505939 | -0.314656 | -0.275442 | -0.396900 |
75% | 0.875727 | 0.452558 | 0.860431 | 0.116501 |
max | 1.565294 | 2.301889 | 1.192366 | 0.478628 |
df.T
2013-01-01 00:00:00 | 2013-01-02 00:00:00 | 2013-01-03 00:00:00 | 2013-01-04 00:00:00 | 2013-01-05 00:00:00 | 2013-01-06 00:00:00 | |
---|---|---|---|---|---|---|
A | 0.830988 | -1.314992 | 0.890640 | 1.565294 | 0.180890 | -0.050440 |
B | 0.211301 | 0.532977 | -1.036566 | -0.901578 | 2.301889 | -0.840614 |
C | -0.926818 | 1.192366 | -2.189510 | 1.148267 | -0.003075 | -0.547810 |
D | -0.613411 | -1.106847 | -0.397050 | 0.287584 | 0.478628 | -0.396750 |
df.sort_index(axis=1, ascending=False)
D | C | B | A | |
---|---|---|---|---|
2013-01-01 | -0.613411 | -0.926818 | 0.211301 | 0.830988 |
2013-01-02 | -1.106847 | 1.192366 | 0.532977 | -1.314992 |
2013-01-03 | -0.397050 | -2.189510 | -1.036566 | 0.890640 |
2013-01-04 | 0.287584 | 1.148267 | -0.901578 | 1.565294 |
2013-01-05 | 0.478628 | -0.003075 | 2.301889 | 0.180890 |
2013-01-06 | -0.396750 | -0.547810 | -0.840614 | -0.050440 |
df.sort_values(by='B')
A | B | C | D | |
---|---|---|---|---|
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -0.396750 |
2013-01-01 | 0.830988 | 0.211301 | -0.926818 | -0.613411 |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 |
df.sort_values(by=['C', 'B'])
A | B | C | D | |
---|---|---|---|---|
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 |
2013-01-01 | 0.830988 | 0.211301 | -0.926818 | -0.613411 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -0.396750 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 |
df['A']
2013-01-01 0.830988 2013-01-02 -1.314992 2013-01-03 0.890640 2013-01-04 1.565294 2013-01-05 0.180890 2013-01-06 -0.050440 Freq: D, Name: A, dtype: float64
df[0:3]
A | B | C | D | |
---|---|---|---|---|
2013-01-01 | 0.830988 | 0.211301 | -0.926818 | -0.613411 |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 |
df['20130102': '20130104']
A | B | C | D | |
---|---|---|---|---|
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 |
df.loc[dates[0]]
A 0.830988 B 0.211301 C -0.926818 D -0.613411 Name: 2013-01-01 00:00:00, dtype: float64
df.loc[:, ['A', 'B']]
A | B | |
---|---|---|
2013-01-01 | 0.830988 | 0.211301 |
2013-01-02 | -1.314992 | 0.532977 |
2013-01-03 | 0.890640 | -1.036566 |
2013-01-04 | 1.565294 | -0.901578 |
2013-01-05 | 0.180890 | 2.301889 |
2013-01-06 | -0.050440 | -0.840614 |
df.loc['20130102': '20130104', ['A', 'B']]
A | B | |
---|---|---|
2013-01-02 | -1.314992 | 0.532977 |
2013-01-03 | 0.890640 | -1.036566 |
2013-01-04 | 1.565294 | -0.901578 |
df.loc['20130102', ['A', 'B']]
A -1.314992 B 0.532977 Name: 2013-01-02 00:00:00, dtype: float64
df.loc[dates[0], 'A']
0.83098767923609629
df.at[dates[0], 'A']
0.83098767923609629
df.iloc[3]
A 1.565294 B -0.901578 C 1.148267 D 0.287584 Name: 2013-01-04 00:00:00, dtype: float64
df.iloc[3:5, 0:2]
A | B | |
---|---|---|
2013-01-04 | 1.565294 | -0.901578 |
2013-01-05 | 0.180890 | 2.301889 |
df.iloc[[1, 2, 4], [0, 2]]
A | C | |
---|---|---|
2013-01-02 | -1.314992 | 1.192366 |
2013-01-03 | 0.890640 | -2.189510 |
2013-01-05 | 0.180890 | -0.003075 |
df.iloc[1:3, :]
A | B | C | D | |
---|---|---|---|---|
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 |
df.iloc[:, 1:3]
B | C | |
---|---|---|
2013-01-01 | 0.211301 | -0.926818 |
2013-01-02 | 0.532977 | 1.192366 |
2013-01-03 | -1.036566 | -2.189510 |
2013-01-04 | -0.901578 | 1.148267 |
2013-01-05 | 2.301889 | -0.003075 |
2013-01-06 | -0.840614 | -0.547810 |
df.iloc[1, 1]
0.53297705530790285
df.iat[1, 1]
0.53297705530790285
df[df.A > 0]
A | B | C | D | |
---|---|---|---|---|
2013-01-01 | 0.830988 | 0.211301 | -0.926818 | -0.613411 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 |
df[df > 0]
A | B | C | D | |
---|---|---|---|---|
2013-01-01 | 0.830988 | 0.211301 | NaN | NaN |
2013-01-02 | NaN | 0.532977 | 1.192366 | NaN |
2013-01-03 | 0.890640 | NaN | NaN | NaN |
2013-01-04 | 1.565294 | NaN | 1.148267 | 0.287584 |
2013-01-05 | 0.180890 | 2.301889 | NaN | 0.478628 |
2013-01-06 | NaN | NaN | NaN | NaN |
df2 = df.copy()
df2['E'] = ['one', 'one', 'two', 'three', 'four', 'three']
df2
A | B | C | D | E | |
---|---|---|---|---|---|
2013-01-01 | 0.830988 | 0.211301 | -0.926818 | -0.613411 | one |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 | one |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 | two |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 | three |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 | four |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -0.396750 | three |
df2[df2['E'].isin(['two', 'four'])]
A | B | C | D | E | |
---|---|---|---|---|---|
2013-01-03 | 0.89064 | -1.036566 | -2.189510 | -0.397050 | two |
2013-01-05 | 0.18089 | 2.301889 | -0.003075 | 0.478628 | four |
s1 = pd.Series([1, 2, 3, 4, 5, 6], index=pd.date_range('20130102', periods=6))
s1
2013-01-02 1 2013-01-03 2 2013-01-04 3 2013-01-05 4 2013-01-06 5 2013-01-07 6 Freq: D, dtype: int64
df['F'] = s1
df
A | B | C | D | F | |
---|---|---|---|---|---|
2013-01-01 | 0.830988 | 0.211301 | -0.926818 | -0.613411 | NaN |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 | 1.0 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 | 2.0 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 | 3.0 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 | 4.0 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -0.396750 | 5.0 |
df.at[dates[0], 'A'] = 0
df
A | B | C | D | F | |
---|---|---|---|---|---|
2013-01-01 | 0.000000 | 0.211301 | -0.926818 | -0.613411 | NaN |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 | 1.0 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 | 2.0 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 | 3.0 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 | 4.0 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -0.396750 | 5.0 |
df.iat[0, 1] = 0
df
A | B | C | D | F | |
---|---|---|---|---|---|
2013-01-01 | 0.000000 | 0.000000 | -0.926818 | -0.613411 | NaN |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | -1.106847 | 1.0 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | -0.397050 | 2.0 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 0.287584 | 3.0 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 0.478628 | 4.0 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -0.396750 | 5.0 |
df.loc[:, 'D'] = np.array([5] * len(df))
df
A | B | C | D | F | |
---|---|---|---|---|---|
2013-01-01 | 0.000000 | 0.000000 | -0.926818 | 5 | NaN |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | 5 | 1.0 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | 5 | 2.0 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 5 | 3.0 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 5 | 4.0 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | 5 | 5.0 |
df2 = df.copy()
df2[df2 > 0] = -df2
df2
A | B | C | D | F | |
---|---|---|---|---|---|
2013-01-01 | 0.000000 | 0.000000 | -0.926818 | -5 | NaN |
2013-01-02 | -1.314992 | -0.532977 | -1.192366 | -5 | -1.0 |
2013-01-03 | -0.890640 | -1.036566 | -2.189510 | -5 | -2.0 |
2013-01-04 | -1.565294 | -0.901578 | -1.148267 | -5 | -3.0 |
2013-01-05 | -0.180890 | -2.301889 | -0.003075 | -5 | -4.0 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | -5 | -5.0 |
pandas 主要使用 np.nan 替换丢失的数据. 默认情况下它并不包含在计算中.
df1 = df.reindex(index=dates[0:4], columns=list(df.columns) + ['E'])
df1.loc[dates[0]: dates[1], 'E'] = 1
df1
A | B | C | D | F | E | |
---|---|---|---|---|---|---|
2013-01-01 | 0.000000 | 0.000000 | -0.926818 | 5 | NaN | 1.0 |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | 5 | 1.0 | 1.0 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | 5 | 2.0 | NaN |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 5 | 3.0 | NaN |
df1.dropna(how='any')
A | B | C | D | F | E | |
---|---|---|---|---|---|---|
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | 5 | 1.0 | 1.0 |
df1.fillna(value=5)
A | B | C | D | F | E | |
---|---|---|---|---|---|---|
2013-01-01 | 0.000000 | 0.000000 | -0.926818 | 5 | 5.0 | 1.0 |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | 5 | 1.0 | 1.0 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | 5 | 2.0 | 5.0 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 5 | 3.0 | 5.0 |
pd.isnull(df1)
A | B | C | D | F | E | |
---|---|---|---|---|---|---|
2013-01-01 | False | False | False | False | True | False |
2013-01-02 | False | False | False | False | False | False |
2013-01-03 | False | False | False | False | False | True |
2013-01-04 | False | False | False | False | False | True |
计算时一般不包括丢失的数据
df.mean() # axis参数默认为0, 表示 index 轴
A 0.211899 B 0.009351 C -0.221097 D 5.000000 F 3.000000 dtype: float64
df.mean(axis=1)
2013-01-01 1.018295 2013-01-02 1.282070 2013-01-03 0.932913 2013-01-04 1.962396 2013-01-05 2.295941 2013-01-06 1.712227 Freq: D, dtype: float64
s = pd.Series([1, 3, 5, np.nan, 6, 8], index=dates).shift(2)
s
2013-01-01 NaN 2013-01-02 NaN 2013-01-03 1.0 2013-01-04 3.0 2013-01-05 5.0 2013-01-06 NaN Freq: D, dtype: float64
df
A | B | C | D | F | |
---|---|---|---|---|---|
2013-01-01 | 0.000000 | 0.000000 | -0.926818 | 5 | NaN |
2013-01-02 | -1.314992 | 0.532977 | 1.192366 | 5 | 1.0 |
2013-01-03 | 0.890640 | -1.036566 | -2.189510 | 5 | 2.0 |
2013-01-04 | 1.565294 | -0.901578 | 1.148267 | 5 | 3.0 |
2013-01-05 | 0.180890 | 2.301889 | -0.003075 | 5 | 4.0 |
2013-01-06 | -0.050440 | -0.840614 | -0.547810 | 5 | 5.0 |
df.sub(s, axis=0)
A | B | C | D | F | |
---|---|---|---|---|---|
2013-01-01 | NaN | NaN | NaN | NaN | NaN |
2013-01-02 | NaN | NaN | NaN | NaN | NaN |
2013-01-03 | -0.109360 | -2.036566 | -3.189510 | 4.0 | 1.0 |
2013-01-04 | -1.434706 | -3.901578 | -1.851733 | 2.0 | 0.0 |
2013-01-05 | -4.819110 | -2.698111 | -5.003075 | 0.0 | -1.0 |
2013-01-06 | NaN | NaN | NaN | NaN | NaN |
df.apply(np.cumsum)
A | B | C | D | F | |
---|---|---|---|---|---|
2013-01-01 | 0.000000 | 0.000000 | -0.926818 | 5 | NaN |
2013-01-02 | -1.314992 | 0.532977 | 0.265548 | 10 | 1.0 |
2013-01-03 | -0.424352 | -0.503589 | -1.923963 | 15 | 3.0 |
2013-01-04 | 1.140942 | -1.405167 | -0.775696 | 20 | 6.0 |
2013-01-05 | 1.321832 | 0.896721 | -0.778771 | 25 | 10.0 |
2013-01-06 | 1.271392 | 0.056107 | -1.326580 | 30 | 15.0 |
df.apply(lambda x: x.max() - x.min())
A 2.880286 B 3.338455 C 3.381876 D 0.000000 F 4.000000 dtype: float64
s = pd.Series(np.random.randint(0, 7, size=10))
s
0 3 1 0 2 6 3 6 4 1 5 3 6 4 7 2 8 5 9 4 dtype: int64
s.value_counts()
6 2 4 2 3 2 5 1 2 1 1 1 0 1 dtype: int64
s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
s.str.lower()
0 a 1 b 2 c 3 aaba 4 baca 5 NaN 6 caba 7 dog 8 cat dtype: object
pandas 提供各种工具以简便合并序列, 数据帧, 和组合对象. 在 连接/合并 类型操作中, 使用多种类型索引和相关数学函数.
df = pd.DataFrame(np.random.randn(10, 4))
df
0 | 1 | 2 | 3 | |
---|---|---|---|---|
0 | 1.198139 | 0.255351 | -2.163206 | -0.546918 |
1 | -0.757948 | 0.719486 | 0.944935 | 0.961493 |
2 | -1.231672 | -0.301289 | 0.015839 | 0.183131 |
3 | 1.005350 | 0.040537 | 1.347831 | 0.562388 |
4 | -1.560731 | 0.127616 | 2.606517 | 0.994567 |
5 | 1.243707 | -0.522960 | 0.073443 | 0.483926 |
6 | 1.651448 | 0.254195 | 0.295707 | -2.312916 |
7 | -0.208332 | -1.197274 | 2.738847 | 0.038823 |
8 | -0.295732 | -0.211062 | 0.181727 | 0.827109 |
9 | 1.247613 | 0.318213 | -0.525624 | 0.119192 |
pieces = [df[:3], df[3:7], df[7:]]
pieces
[ 0 1 2 3 0 1.198139 0.255351 -2.163206 -0.546918 1 -0.757948 0.719486 0.944935 0.961493 2 -1.231672 -0.301289 0.015839 0.183131, 0 1 2 3 3 1.005350 0.040537 1.347831 0.562388 4 -1.560731 0.127616 2.606517 0.994567 5 1.243707 -0.522960 0.073443 0.483926 6 1.651448 0.254195 0.295707 -2.312916, 0 1 2 3 7 -0.208332 -1.197274 2.738847 0.038823 8 -0.295732 -0.211062 0.181727 0.827109 9 1.247613 0.318213 -0.525624 0.119192]
pd.concat(pieces)
0 | 1 | 2 | 3 | |
---|---|---|---|---|
0 | 1.198139 | 0.255351 | -2.163206 | -0.546918 |
1 | -0.757948 | 0.719486 | 0.944935 | 0.961493 |
2 | -1.231672 | -0.301289 | 0.015839 | 0.183131 |
3 | 1.005350 | 0.040537 | 1.347831 | 0.562388 |
4 | -1.560731 | 0.127616 | 2.606517 | 0.994567 |
5 | 1.243707 | -0.522960 | 0.073443 | 0.483926 |
6 | 1.651448 | 0.254195 | 0.295707 | -2.312916 |
7 | -0.208332 | -1.197274 | 2.738847 | 0.038823 |
8 | -0.295732 | -0.211062 | 0.181727 | 0.827109 |
9 | 1.247613 | 0.318213 | -0.525624 | 0.119192 |
left = pd.DataFrame({'key': ['foo', 'foo'], 'lval': [1, 2]})
right = pd.DataFrame({'key': ['foo', 'foo'], 'rval': [4, 5]})
left
key | lval | |
---|---|---|
0 | foo | 1 |
1 | foo | 2 |
right
key | rval | |
---|---|---|
0 | foo | 4 |
1 | foo | 5 |
pd.merge(left, right, on='key')
key | lval | rval | |
---|---|---|---|
0 | foo | 1 | 4 |
1 | foo | 1 | 5 |
2 | foo | 2 | 4 |
3 | foo | 2 | 5 |
df = pd.DataFrame(np.random.randn(8, 4), columns=['A', 'B', 'C', 'D'])
df
A | B | C | D | |
---|---|---|---|---|
0 | -1.114572 | 0.097531 | 0.022282 | 0.219714 |
1 | 1.040871 | -2.641861 | -0.197795 | -0.430224 |
2 | 1.064996 | -0.815516 | 2.375643 | -2.706566 |
3 | 0.208141 | 0.107715 | -0.163068 | 0.252386 |
4 | 0.921251 | -0.336959 | 0.502700 | 0.802547 |
5 | 0.047286 | 2.025958 | 0.954283 | 1.381018 |
6 | 0.518963 | -1.539909 | 0.021547 | 1.477309 |
7 | -0.106894 | 0.862488 | -0.828176 | -0.815590 |
s = df.iloc[3]
df.append(s, ignore_index=True)
A | B | C | D | |
---|---|---|---|---|
0 | -1.114572 | 0.097531 | 0.022282 | 0.219714 |
1 | 1.040871 | -2.641861 | -0.197795 | -0.430224 |
2 | 1.064996 | -0.815516 | 2.375643 | -2.706566 |
3 | 0.208141 | 0.107715 | -0.163068 | 0.252386 |
4 | 0.921251 | -0.336959 | 0.502700 | 0.802547 |
5 | 0.047286 | 2.025958 | 0.954283 | 1.381018 |
6 | 0.518963 | -1.539909 | 0.021547 | 1.477309 |
7 | -0.106894 | 0.862488 | -0.828176 | -0.815590 |
8 | 0.208141 | 0.107715 | -0.163068 | 0.252386 |
对于 "group by" 指的是以下一个或多个处理:
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar'],
'B': ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
'C': np.random.randn(8),
'D': np.random.randn(8)})
df
A | B | C | D | |
---|---|---|---|---|
0 | foo | one | -0.322029 | 0.593835 |
1 | bar | one | -1.485272 | 0.700787 |
2 | foo | two | 0.914429 | 0.699238 |
3 | bar | three | -1.552597 | -0.003782 |
4 | foo | two | 3.025511 | 0.586944 |
5 | bar | two | 0.499808 | 0.383772 |
6 | foo | one | -0.263149 | -0.431824 |
7 | bar | three | 0.967752 | 0.946886 |
df.groupby('A').sum()
C | D | |
---|---|---|
A | ||
bar | -1.570308 | 2.027663 |
foo | 3.354763 | 1.448194 |
df.groupby(['A', 'B']).sum()
C | D | ||
---|---|---|---|
A | B | ||
bar | one | -1.485272 | 0.700787 |
three | -0.584845 | 0.943104 | |
two | 0.499808 | 0.383772 | |
foo | one | -0.585178 | 0.162011 |
two | 3.939940 | 1.286183 |
tuples = list(zip(*[['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two','one', 'two', 'one', 'two']]))
tuples
[('bar', 'one'), ('bar', 'two'), ('baz', 'one'), ('baz', 'two'), ('foo', 'one'), ('foo', 'two'), ('qux', 'one'), ('qux', 'two')]
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'seconds'])
df = pd.DataFrame(np.random.randn(8, 2), index=index, columns=['A', 'B'])
df
A | B | ||
---|---|---|---|
first | seconds | ||
bar | one | -0.558695 | 0.105423 |
two | 0.271188 | -0.217300 | |
baz | one | 0.093175 | -0.225239 |
two | -0.093316 | -0.791467 | |
foo | one | -0.145413 | 0.126640 |
two | 1.120556 | 1.117124 | |
qux | one | -1.304878 | -1.166168 |
two | 0.522716 | 0.857816 |
df2 = df[:4]
df2
A | B | ||
---|---|---|---|
first | seconds | ||
bar | one | -0.558695 | 0.105423 |
two | 0.271188 | -0.217300 | |
baz | one | 0.093175 | -0.225239 |
two | -0.093316 | -0.791467 |
stacked = df2.stack()
stacked
first seconds bar one A -0.558695 B 0.105423 two A 0.271188 B -0.217300 baz one A 0.093175 B -0.225239 two A -0.093316 B -0.791467 dtype: float64
stacked.unstack()
A | B | ||
---|---|---|---|
first | seconds | ||
bar | one | -0.558695 | 0.105423 |
two | 0.271188 | -0.217300 | |
baz | one | 0.093175 | -0.225239 |
two | -0.093316 | -0.791467 |
stacked.unstack(level=1)
seconds | one | two | |
---|---|---|---|
first | |||
bar | A | -0.558695 | 0.271188 |
B | 0.105423 | -0.217300 | |
baz | A | 0.093175 | -0.093316 |
B | -0.225239 | -0.791467 |
stacked.unstack(level=0)
first | bar | baz | |
---|---|---|---|
seconds | |||
one | A | -0.558695 | 0.093175 |
B | 0.105423 | -0.225239 | |
two | A | 0.271188 | -0.093316 |
B | -0.217300 | -0.791467 |
df = pd.DataFrame({'A': ['one', 'one', 'two', 'three'] * 3,
'B': ['A', 'B', 'C'] * 4,
'C': ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
'D': np.random.randn(12),
'E': np.random.randn(12)})
df
A | B | C | D | E | |
---|---|---|---|---|---|
0 | one | A | foo | 1.894734 | -2.293275 |
1 | one | B | foo | -1.362782 | -0.130090 |
2 | two | C | foo | 0.843821 | 0.649588 |
3 | three | A | bar | 0.496000 | -0.623999 |
4 | one | B | bar | 0.457438 | -0.495746 |
5 | one | C | bar | -0.645673 | -0.517788 |
6 | two | A | foo | -1.247229 | 0.242816 |
7 | three | B | foo | 1.666903 | 1.620036 |
8 | one | C | foo | -0.585036 | -0.344293 |
9 | one | A | bar | 0.277802 | 0.688129 |
10 | two | B | bar | 0.988346 | 0.868884 |
11 | three | C | bar | -2.202665 | 0.232460 |
pd.pivot_table(df, values='D', index=['A', 'B'], columns=['C'])
C | bar | foo | |
---|---|---|---|
A | B | ||
one | A | 0.277802 | 1.894734 |
B | 0.457438 | -1.362782 | |
C | -0.645673 | -0.585036 | |
three | A | 0.496000 | NaN |
B | NaN | 1.666903 | |
C | -2.202665 | NaN | |
two | A | NaN | -1.247229 |
B | 0.988346 | NaN | |
C | NaN | 0.843821 |
pandas 有易用, 强大且高效的函数用于高频数据重采样转换操作(例如: 转换秒数据到5分钟数据).
这是很普通的情况, 但不局限于金融应用.
rng = pd.date_range('1/1/2012', periods=100, freq='S')
ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng)
ts.resample('5MIN').sum()
2012-01-01 21689 Freq: 5T, dtype: int64
rng = pd.date_range('3/6/2012 00:00', periods=5, freq='D')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
ts
2012-03-06 -0.766239 2012-03-07 0.453263 2012-03-08 -0.490956 2012-03-09 -1.291874 2012-03-10 -0.463390 Freq: D, dtype: float64
ts_utc = ts.tz_localize('UTC')
ts_utc
2012-03-06 00:00:00+00:00 -0.766239 2012-03-07 00:00:00+00:00 0.453263 2012-03-08 00:00:00+00:00 -0.490956 2012-03-09 00:00:00+00:00 -1.291874 2012-03-10 00:00:00+00:00 -0.463390 Freq: D, dtype: float64
ts_utc.tz_convert('US/Eastern')
2012-03-05 19:00:00-05:00 -0.766239 2012-03-06 19:00:00-05:00 0.453263 2012-03-07 19:00:00-05:00 -0.490956 2012-03-08 19:00:00-05:00 -1.291874 2012-03-09 19:00:00-05:00 -0.463390 Freq: D, dtype: float64
rng = pd.date_range('1/1/2012', periods=5, freq='M')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
ts
2012-01-31 0.095301 2012-02-29 0.408777 2012-03-31 -0.790425 2012-04-30 0.090653 2012-05-31 0.317007 Freq: M, dtype: float64
ps = ts.to_period()
ps
2012-01 0.095301 2012-02 0.408777 2012-03 -0.790425 2012-04 0.090653 2012-05 0.317007 Freq: M, dtype: float64
ps.to_timestamp()
2012-01-01 0.095301 2012-02-01 0.408777 2012-03-01 -0.790425 2012-04-01 0.090653 2012-05-01 0.317007 Freq: MS, dtype: float64
prng = pd.period_range('1990Q1', '2004Q4', freq='Q-NOV')
ts = pd.Series(np.random.randn(len(prng)), index=prng)
ts.head()
1990Q1 1.795697 1990Q2 0.311190 1990Q3 0.626286 1990Q4 -3.022472 1991Q1 0.482668 Freq: Q-NOV, dtype: float64
ts.index = (prng.asfreq('M', 'e') + 1).asfreq('H', 's') + 9
ts.head()
1990-03-01 09:00 1.795697 1990-06-01 09:00 0.311190 1990-09-01 09:00 0.626286 1990-12-01 09:00 -3.022472 1991-03-01 09:00 0.482668 Freq: H, dtype: float64
df = pd.DataFrame({'id': [1, 2, 3, 4, 5, 6], 'raw_grade': ['a', 'b', 'b', 'a', 'a', 'e']})
df['grade'] = df['raw_grade'].astype('category')
df['grade']
0 a 1 b 2 b 3 a 4 a 5 e Name: grade, dtype: category Categories (3, object): [a, b, e]
df['grade'].cat.categories = ['very good', 'good', 'very bad']
df['grade']
0 very good 1 good 2 good 3 very good 4 very good 5 very bad Name: grade, dtype: category Categories (3, object): [very good, good, very bad]
df['grade'] = df['grade'].cat.set_categories(['very bad', 'bad', 'medium', 'good', 'very good'])
df['grade']
0 very good 1 good 2 good 3 very good 4 very good 5 very bad Name: grade, dtype: category Categories (5, object): [very bad, bad, medium, good, very good]
df.sort_values('grade')
id | raw_grade | grade | |
---|---|---|---|
5 | 6 | e | very bad |
1 | 2 | b | good |
2 | 3 | b | good |
0 | 1 | a | very good |
3 | 4 | a | very good |
4 | 5 | a | very good |
df.groupby('grade').size()
grade very bad 1 bad 0 medium 0 good 2 very good 3 dtype: int64
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x1144bfad0>
plt.show()
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=['A', 'B', 'C', 'D'])
df = df.cumsum()
plt.figure()
df.plot()
plt.legend(loc='best')
<matplotlib.legend.Legend at 0x114654850>
plt.show()
<matplotlib.figure.Figure at 0x1146633d0>
df.to_csv('temp_file_foo.csv')
pd.read_csv('temp_file_foo.csv')
Unnamed: 0 | A | B | C | D | |
---|---|---|---|---|---|
0 | 2000-01-01 | -1.199395 | 1.387735 | -1.798714 | -0.633652 |
1 | 2000-01-02 | -0.908396 | 1.301464 | -2.751684 | -0.756612 |
2 | 2000-01-03 | -1.214637 | 1.722991 | -2.878235 | -1.103410 |
3 | 2000-01-04 | -1.444817 | 1.526782 | -1.434901 | -0.878478 |
4 | 2000-01-05 | -2.336566 | 0.792154 | 0.702733 | -1.161456 |
5 | 2000-01-06 | -1.141497 | -0.123991 | 0.006881 | -0.231437 |
6 | 2000-01-07 | -0.903127 | -0.106136 | -0.105336 | 0.636556 |
7 | 2000-01-08 | -0.363628 | 0.484380 | 0.604074 | 2.070136 |
8 | 2000-01-09 | -2.381704 | -1.328455 | 2.261637 | -0.153917 |
9 | 2000-01-10 | -2.071101 | -1.512707 | 3.693099 | -0.840669 |
10 | 2000-01-11 | -2.565354 | 0.130182 | 1.843764 | -1.024025 |
11 | 2000-01-12 | -2.319995 | -0.495654 | 1.502985 | 0.329354 |
12 | 2000-01-13 | -3.597537 | -0.941485 | 2.316260 | 0.292277 |
13 | 2000-01-14 | -2.936507 | -1.304660 | 1.623378 | 2.056469 |
14 | 2000-01-15 | -3.434638 | -0.557851 | 3.005293 | 2.351642 |
15 | 2000-01-16 | -4.416633 | -0.263922 | 3.217599 | 1.910207 |
16 | 2000-01-17 | -3.620688 | 2.576329 | 3.666597 | 3.099960 |
17 | 2000-01-18 | -2.781963 | 2.665356 | 4.350962 | 3.136723 |
18 | 2000-01-19 | -3.103494 | 2.206880 | 2.800751 | 3.927562 |
19 | 2000-01-20 | -4.747767 | 3.565885 | 3.328753 | 5.492230 |
20 | 2000-01-21 | -3.959743 | 3.567764 | 0.668938 | 4.408660 |
21 | 2000-01-22 | -4.307452 | 4.313845 | 0.268082 | 4.341462 |
22 | 2000-01-23 | -4.820593 | 3.535090 | -0.237196 | 3.653925 |
23 | 2000-01-24 | -4.343503 | 3.313142 | 0.196462 | 3.228989 |
24 | 2000-01-25 | -4.012244 | 2.340642 | -0.239219 | 2.294877 |
25 | 2000-01-26 | -5.584496 | 2.627301 | -0.933413 | 2.826616 |
26 | 2000-01-27 | -5.349654 | 1.431231 | -1.747397 | 3.038043 |
27 | 2000-01-28 | -7.274830 | 2.160869 | -1.533647 | 3.606827 |
28 | 2000-01-29 | -7.485718 | 1.098004 | -1.062377 | 3.421171 |
29 | 2000-01-30 | -6.304430 | -0.640919 | -1.360975 | 2.629127 |
... | ... | ... | ... | ... | ... |
970 | 2002-08-28 | -91.161762 | -18.283552 | 12.647657 | -18.508526 |
971 | 2002-08-29 | -89.573510 | -18.504441 | 14.460417 | -17.223896 |
972 | 2002-08-30 | -88.798781 | -16.765993 | 16.420495 | -18.875415 |
973 | 2002-08-31 | -88.407509 | -17.379462 | 16.765101 | -20.467720 |
974 | 2002-09-01 | -89.670998 | -16.868724 | 15.976802 | -20.654874 |
975 | 2002-09-02 | -87.923717 | -18.770030 | 16.433847 | -18.946714 |
976 | 2002-09-03 | -85.777104 | -20.938777 | 17.576698 | -19.501421 |
977 | 2002-09-04 | -85.720509 | -19.315577 | 15.530183 | -18.799975 |
978 | 2002-09-05 | -86.116354 | -19.413728 | 13.943714 | -18.217563 |
979 | 2002-09-06 | -86.582680 | -20.141059 | 14.162898 | -17.635551 |
980 | 2002-09-07 | -86.085200 | -19.333936 | 13.006658 | -18.078151 |
981 | 2002-09-08 | -84.737067 | -18.058932 | 14.705133 | -17.673837 |
982 | 2002-09-09 | -84.024475 | -17.711860 | 15.487204 | -16.985294 |
983 | 2002-09-10 | -83.368774 | -17.535428 | 16.391717 | -16.527879 |
984 | 2002-09-11 | -84.670374 | -18.167918 | 16.634557 | -16.062619 |
985 | 2002-09-12 | -85.539085 | -17.902050 | 16.435134 | -16.825358 |
986 | 2002-09-13 | -85.822989 | -17.396826 | 15.872258 | -16.078469 |
987 | 2002-09-14 | -86.006952 | -18.925765 | 15.711982 | -15.066963 |
988 | 2002-09-15 | -84.027412 | -18.777929 | 17.269961 | -14.160437 |
989 | 2002-09-16 | -84.371619 | -20.118414 | 15.642104 | -15.423790 |
990 | 2002-09-17 | -85.164808 | -19.817076 | 13.001907 | -15.164830 |
991 | 2002-09-18 | -84.218649 | -19.546377 | 15.276487 | -15.387791 |
992 | 2002-09-19 | -83.044203 | -19.228630 | 15.735577 | -14.381051 |
993 | 2002-09-20 | -85.338968 | -20.112770 | 15.090700 | -15.749164 |
994 | 2002-09-21 | -85.016944 | -19.630807 | 14.161316 | -17.186947 |
995 | 2002-09-22 | -86.204378 | -20.593557 | 14.169823 | -18.647361 |
996 | 2002-09-23 | -87.236501 | -19.624129 | 13.717445 | -18.860626 |
997 | 2002-09-24 | -85.017293 | -18.796620 | 12.349552 | -19.443635 |
998 | 2002-09-25 | -82.876770 | -19.974321 | 13.262328 | -22.083206 |
999 | 2002-09-26 | -83.219573 | -20.518671 | 14.674183 | -21.022386 |
1000 rows × 5 columns
df.to_hdf('temp_file_foo.h5', key='df')
pd.read_hdf('temp_file_foo.h5', key='df')
A | B | C | D | |
---|---|---|---|---|
2000-01-01 | -1.199395 | 1.387735 | -1.798714 | -0.633652 |
2000-01-02 | -0.908396 | 1.301464 | -2.751684 | -0.756612 |
2000-01-03 | -1.214637 | 1.722991 | -2.878235 | -1.103410 |
2000-01-04 | -1.444817 | 1.526782 | -1.434901 | -0.878478 |
2000-01-05 | -2.336566 | 0.792154 | 0.702733 | -1.161456 |
2000-01-06 | -1.141497 | -0.123991 | 0.006881 | -0.231437 |
2000-01-07 | -0.903127 | -0.106136 | -0.105336 | 0.636556 |
2000-01-08 | -0.363628 | 0.484380 | 0.604074 | 2.070136 |
2000-01-09 | -2.381704 | -1.328455 | 2.261637 | -0.153917 |
2000-01-10 | -2.071101 | -1.512707 | 3.693099 | -0.840669 |
2000-01-11 | -2.565354 | 0.130182 | 1.843764 | -1.024025 |
2000-01-12 | -2.319995 | -0.495654 | 1.502985 | 0.329354 |
2000-01-13 | -3.597537 | -0.941485 | 2.316260 | 0.292277 |
2000-01-14 | -2.936507 | -1.304660 | 1.623378 | 2.056469 |
2000-01-15 | -3.434638 | -0.557851 | 3.005293 | 2.351642 |
2000-01-16 | -4.416633 | -0.263922 | 3.217599 | 1.910207 |
2000-01-17 | -3.620688 | 2.576329 | 3.666597 | 3.099960 |
2000-01-18 | -2.781963 | 2.665356 | 4.350962 | 3.136723 |
2000-01-19 | -3.103494 | 2.206880 | 2.800751 | 3.927562 |
2000-01-20 | -4.747767 | 3.565885 | 3.328753 | 5.492230 |
2000-01-21 | -3.959743 | 3.567764 | 0.668938 | 4.408660 |
2000-01-22 | -4.307452 | 4.313845 | 0.268082 | 4.341462 |
2000-01-23 | -4.820593 | 3.535090 | -0.237196 | 3.653925 |
2000-01-24 | -4.343503 | 3.313142 | 0.196462 | 3.228989 |
2000-01-25 | -4.012244 | 2.340642 | -0.239219 | 2.294877 |
2000-01-26 | -5.584496 | 2.627301 | -0.933413 | 2.826616 |
2000-01-27 | -5.349654 | 1.431231 | -1.747397 | 3.038043 |
2000-01-28 | -7.274830 | 2.160869 | -1.533647 | 3.606827 |
2000-01-29 | -7.485718 | 1.098004 | -1.062377 | 3.421171 |
2000-01-30 | -6.304430 | -0.640919 | -1.360975 | 2.629127 |
... | ... | ... | ... | ... |
2002-08-28 | -91.161762 | -18.283552 | 12.647657 | -18.508526 |
2002-08-29 | -89.573510 | -18.504441 | 14.460417 | -17.223896 |
2002-08-30 | -88.798781 | -16.765993 | 16.420495 | -18.875415 |
2002-08-31 | -88.407509 | -17.379462 | 16.765101 | -20.467720 |
2002-09-01 | -89.670998 | -16.868724 | 15.976802 | -20.654874 |
2002-09-02 | -87.923717 | -18.770030 | 16.433847 | -18.946714 |
2002-09-03 | -85.777104 | -20.938777 | 17.576698 | -19.501421 |
2002-09-04 | -85.720509 | -19.315577 | 15.530183 | -18.799975 |
2002-09-05 | -86.116354 | -19.413728 | 13.943714 | -18.217563 |
2002-09-06 | -86.582680 | -20.141059 | 14.162898 | -17.635551 |
2002-09-07 | -86.085200 | -19.333936 | 13.006658 | -18.078151 |
2002-09-08 | -84.737067 | -18.058932 | 14.705133 | -17.673837 |
2002-09-09 | -84.024475 | -17.711860 | 15.487204 | -16.985294 |
2002-09-10 | -83.368774 | -17.535428 | 16.391717 | -16.527879 |
2002-09-11 | -84.670374 | -18.167918 | 16.634557 | -16.062619 |
2002-09-12 | -85.539085 | -17.902050 | 16.435134 | -16.825358 |
2002-09-13 | -85.822989 | -17.396826 | 15.872258 | -16.078469 |
2002-09-14 | -86.006952 | -18.925765 | 15.711982 | -15.066963 |
2002-09-15 | -84.027412 | -18.777929 | 17.269961 | -14.160437 |
2002-09-16 | -84.371619 | -20.118414 | 15.642104 | -15.423790 |
2002-09-17 | -85.164808 | -19.817076 | 13.001907 | -15.164830 |
2002-09-18 | -84.218649 | -19.546377 | 15.276487 | -15.387791 |
2002-09-19 | -83.044203 | -19.228630 | 15.735577 | -14.381051 |
2002-09-20 | -85.338968 | -20.112770 | 15.090700 | -15.749164 |
2002-09-21 | -85.016944 | -19.630807 | 14.161316 | -17.186947 |
2002-09-22 | -86.204378 | -20.593557 | 14.169823 | -18.647361 |
2002-09-23 | -87.236501 | -19.624129 | 13.717445 | -18.860626 |
2002-09-24 | -85.017293 | -18.796620 | 12.349553 | -19.443635 |
2002-09-25 | -82.876770 | -19.974321 | 13.262328 | -22.083206 |
2002-09-26 | -83.219573 | -20.518671 | 14.674183 | -21.022386 |
1000 rows × 4 columns
df.to_excel('temp_file_foo.xlsx', sheet_name='Sheet1')
pd.read_excel('temp_file_foo.xlsx', sheetname='Sheet1', index_col=None, na_values=['NA'])
A | B | C | D | |
---|---|---|---|---|
2000-01-01 | -1.199395 | 1.387735 | -1.798714 | -0.633652 |
2000-01-02 | -0.908396 | 1.301464 | -2.751684 | -0.756612 |
2000-01-03 | -1.214637 | 1.722991 | -2.878235 | -1.103410 |
2000-01-04 | -1.444817 | 1.526782 | -1.434901 | -0.878478 |
2000-01-05 | -2.336566 | 0.792154 | 0.702733 | -1.161456 |
2000-01-06 | -1.141497 | -0.123991 | 0.006881 | -0.231437 |
2000-01-07 | -0.903127 | -0.106136 | -0.105336 | 0.636556 |
2000-01-08 | -0.363628 | 0.484380 | 0.604074 | 2.070136 |
2000-01-09 | -2.381704 | -1.328455 | 2.261637 | -0.153917 |
2000-01-10 | -2.071101 | -1.512707 | 3.693099 | -0.840669 |
2000-01-11 | -2.565354 | 0.130182 | 1.843764 | -1.024025 |
2000-01-12 | -2.319995 | -0.495654 | 1.502985 | 0.329354 |
2000-01-13 | -3.597537 | -0.941485 | 2.316260 | 0.292277 |
2000-01-14 | -2.936507 | -1.304660 | 1.623378 | 2.056469 |
2000-01-15 | -3.434638 | -0.557851 | 3.005293 | 2.351642 |
2000-01-16 | -4.416633 | -0.263922 | 3.217599 | 1.910207 |
2000-01-17 | -3.620688 | 2.576329 | 3.666597 | 3.099960 |
2000-01-18 | -2.781963 | 2.665356 | 4.350962 | 3.136723 |
2000-01-19 | -3.103494 | 2.206880 | 2.800751 | 3.927562 |
2000-01-20 | -4.747767 | 3.565885 | 3.328753 | 5.492230 |
2000-01-21 | -3.959743 | 3.567764 | 0.668938 | 4.408660 |
2000-01-22 | -4.307452 | 4.313845 | 0.268082 | 4.341462 |
2000-01-23 | -4.820593 | 3.535090 | -0.237196 | 3.653925 |
2000-01-24 | -4.343503 | 3.313142 | 0.196462 | 3.228989 |
2000-01-25 | -4.012244 | 2.340642 | -0.239219 | 2.294877 |
2000-01-26 | -5.584496 | 2.627301 | -0.933413 | 2.826616 |
2000-01-27 | -5.349654 | 1.431231 | -1.747397 | 3.038043 |
2000-01-28 | -7.274830 | 2.160869 | -1.533647 | 3.606827 |
2000-01-29 | -7.485718 | 1.098004 | -1.062377 | 3.421171 |
2000-01-30 | -6.304430 | -0.640919 | -1.360975 | 2.629127 |
... | ... | ... | ... | ... |
2002-08-28 | -91.161762 | -18.283552 | 12.647657 | -18.508526 |
2002-08-29 | -89.573510 | -18.504441 | 14.460417 | -17.223896 |
2002-08-30 | -88.798781 | -16.765993 | 16.420495 | -18.875415 |
2002-08-31 | -88.407509 | -17.379462 | 16.765101 | -20.467720 |
2002-09-01 | -89.670998 | -16.868724 | 15.976802 | -20.654874 |
2002-09-02 | -87.923717 | -18.770030 | 16.433847 | -18.946714 |
2002-09-03 | -85.777104 | -20.938777 | 17.576698 | -19.501421 |
2002-09-04 | -85.720509 | -19.315577 | 15.530183 | -18.799975 |
2002-09-05 | -86.116354 | -19.413728 | 13.943714 | -18.217563 |
2002-09-06 | -86.582680 | -20.141059 | 14.162898 | -17.635551 |
2002-09-07 | -86.085200 | -19.333936 | 13.006658 | -18.078151 |
2002-09-08 | -84.737067 | -18.058932 | 14.705133 | -17.673837 |
2002-09-09 | -84.024475 | -17.711860 | 15.487204 | -16.985294 |
2002-09-10 | -83.368774 | -17.535428 | 16.391717 | -16.527879 |
2002-09-11 | -84.670374 | -18.167918 | 16.634557 | -16.062619 |
2002-09-12 | -85.539085 | -17.902050 | 16.435134 | -16.825358 |
2002-09-13 | -85.822989 | -17.396826 | 15.872258 | -16.078469 |
2002-09-14 | -86.006952 | -18.925765 | 15.711982 | -15.066963 |
2002-09-15 | -84.027412 | -18.777929 | 17.269961 | -14.160437 |
2002-09-16 | -84.371619 | -20.118414 | 15.642104 | -15.423790 |
2002-09-17 | -85.164808 | -19.817076 | 13.001907 | -15.164830 |
2002-09-18 | -84.218649 | -19.546377 | 15.276487 | -15.387791 |
2002-09-19 | -83.044203 | -19.228630 | 15.735577 | -14.381051 |
2002-09-20 | -85.338968 | -20.112770 | 15.090700 | -15.749164 |
2002-09-21 | -85.016944 | -19.630807 | 14.161316 | -17.186947 |
2002-09-22 | -86.204378 | -20.593557 | 14.169823 | -18.647361 |
2002-09-23 | -87.236501 | -19.624129 | 13.717445 | -18.860626 |
2002-09-24 | -85.017293 | -18.796620 | 12.349553 | -19.443635 |
2002-09-25 | -82.876770 | -19.974321 | 13.262328 | -22.083206 |
2002-09-26 | -83.219573 | -20.518671 | 14.674183 | -21.022386 |
1000 rows × 4 columns