- 创造数据
- 修改值操作
- 插入一列数据
- 插入相同的值
- 插入不同的值
- 使用Series插入
- 修改单个值
- 按照标签loc
- 按照索引iloc
- 修改多个值
- 按照标签loc
- 按照索引iloc
dates = pd.date_range('20001029',periods=5)
calender = pd.Dataframe(np.arange(15).reshape(5,3),dates,columns=['x','y','z'])
Run:
calendar:
x y z
2000-10-29 0 1 2
2000-10-30 3 4 5
2000-10-31 6 7 8
2000-11-01 9 10 11
2000-11-02 12 13 14
data1 = 20 calender['w'] = data1
Run:
calendar[“w”]:
x y z w
2000-10-29 0 1 2 20
2000-10-30 3 4 5 20
2000-10-31 6 7 8 20
2000-11-01 9 10 11 20
2000-11-02 12 13 14 20
data1 = np.linspace(1,5,5,dtype=int) calender['w'] = data1
Run:
calendar[“w”]:
x y z w
2000-10-29 0 1 2 1
2000-10-30 3 4 5 2
2000-10-31 6 7 8 3
2000-11-01 9 10 11 4
2000-11-02 12 13 14 5
data1 = [1,1,1,1,1] calender['v'] = pd.Series(data1,index=dates)
Run:
calender[“v”]:
x y z v
2000-10-29 0 1 2 1
2000-10-30 3 4 5 1
2000-10-31 6 7 8 1
2000-11-01 9 10 11 1
2000-11-02 12 13 14 1
calender.loc['2000-10-30','x'] = 99
Run:
calender.loc[‘2000-10-30’,‘x’]:
x y z v
2000-10-29 0 1 2 1
2000-10-30 99 4 5 1
2000-10-31 6 7 8 1
2000-11-01 9 10 11 1
2000-11-02 12 13 14 1
calender.iloc[2,2] = 66
Run:
calender.iloc[2,2]:
x y z
2000-10-29 0 1 2
2000-10-30 3 4 5
2000-10-31 6 7 66
2000-11-01 9 10 11
2000-11-02 12 13 14
calender.loc['2000-10-30','x':'y'] = 100
Run:
calender.loc[‘2000-10-30’,‘x’:‘y’]:
x y z
2000-10-29 0 1 2
2000-10-30 100 100 5
2000-10-31 6 7 8
2000-11-01 9 10 11
2000-11-02 12 13 14
calender.iloc[2:3,2] = 100
Run;
calender.iloc[2:3,2]:
x y z
2000-10-29 0 1 2
2000-10-30 3 4 5
2000-10-31 6 7 100
2000-11-01 9 10 11
2000-11-02 12 13 14



