可以访问Series的索引Series 或DataFrame的列 作为属性
import pandas as pdimport numpy as npsa = pd.Series([1, 2, 3], index=list('abc'))print(sa)print(sa.b) # 2,Series 数据用行索引访问
a    1
b    2
c    3
dtype: int64
2
dates = pd.date_range('1/1/2000', periods=8)df = pd.DataFrame(np.random.randn(8, 4),index=dates, columns=['A', 'B', 'C', 'D'])print(df)dfa = df.copy() # 复制一个dateframeprint(dfa.A) # 输出列索引为A的数据
df  输出整个dateframe中的数据
                   A         B         C         D
2000-01-01 -1.164180 -0.074449  0.024508  0.258941
2000-01-02  0.432623  0.609803  2.032749  1.067229
2000-01-03 -1.527508 -0.586559  1.134569  1.394826
2000-01-04  0.549750  1.733102 -0.309395  1.095839
2000-01-05  1.469302 -0.803328  0.039403  0.556420
2000-01-06  0.470629 -0.940261  0.907722  1.765288
2000-01-07  1.937365  0.639491 -1.219057  1.858613
2000-01-08  0.780139  1.296072 -0.793080  0.484197
dfa.A 输出列索引为A的数据
2000-01-01   -1.164180
2000-01-02    0.432623
2000-01-03   -1.527508
2000-01-04    0.549750
2000-01-05    1.469302
2000-01-06    0.470629
2000-01-07    1.937365
2000-01-08    0.780139
Freq: D, Name: A, dtype: float64
sa.a = 5 # 修改sa.a的值为5print(sa)
a    5
b    2
c    3
dtype: int64
dfa.A = list(range(len(dfa.index))) # 用产生的数列替换dateframe中的A列的数据print(dfa)
产生0-7的整数代替dfa.a的索引 
                    A           B            C             D
2000-01-01  0 -0.074449  0.024508  0.258941
2000-01-02  1  0.609803  2.032749  1.067229
2000-01-03  2 -0.586559  1.134569  1.394826
2000-01-04  3  1.733102 -0.309395  1.095839
2000-01-05  4 -0.803328  0.039403  0.556420
2000-01-06  5 -0.940261  0.907722  1.765288
2000-01-07  6  0.639491 -1.219057  1.858613
2000-01-08  7  1.296072 -0.793080  0.484197
dfa['E'] = list(range(len(dfa.index))) # 创建一个新列 Eprint(dfa)
A B C D E<br />2000-01-01 0 -0.074449 0.024508 0.258941 0<br />2000-01-02 1 0.609803 2.032749 1.067229 1<br />2000-01-03 2 -0.586559 1.134569 1.394826 2<br />2000-01-04 3 1.733102 -0.309395 1.095839 3<br />2000-01-05 4 -0.803328 0.039403 0.556420 4<br />2000-01-06 5 -0.940261 0.907722 1.765288 5<br />2000-01-07 6 0.639491 -1.219057 1.858613 6<br />2000-01-08 7 1.296072 -0.793080 0.484197 7
x = pd.DataFrame({'x': [1, 2, 3], 'y': [3, 4, 5]})
print(x)
x.iloc[1] = {'x': 9, 'y': 99} # 修改x中行索引号为1的数据
print(x)
x 的数据
   x  y
0  1  3
1  2  4
2  3  5
修改后的数据
   x   y
0  1   3
1  9  99
2  3   5
