|
环境:
- python 3.7.6
- python-dateutil 2.8.1
- openpyxl 3.0.3
- pandas 1.0.1
- pandoc 2.2.3.2
复制代码 pands基本操作:
(1)获取一列
data2 = data['xy']
(2)删除行,删除 xy列中不等于cb、ds的行
keywords = []
for i in range(0, data.shape[0]):
if(data2 != 'cb' and data2 != 'ds'):
keywords.append(i)
data1 = data.drop(keywords, axis=0)
(3)索引重新从0开始排列
data1 = data1.reset_index(drop=True)
(4)新增 列xxx
data2['xxx'] = 0
(5)排序,按照列hs、project来排序data2 = data2.sort_values( by = ['hs','project'])
data2 = data2.reset_index(drop=True)
(6)按照行、列来处理数据,第i行,第hs列的取值、赋值
data_table.loc[i,'hs'] = data2['hs']
or
data_table.loc[i,'hs'] = data2[i, 'hs']
|
|