df = cun_lte[cun_lte[‘信息’].str.contains(‘R|A’) == True ]
temp = temp[(temp[‘标识’] == “0”) | (temp[‘标识’] == 0)] # 取 0 的
2、单条件判断(if)result[‘干扰’] = np.where(result[‘MAX’] > -107, ‘是’, ‘’)
3、多条件判断(嵌套if)df[‘开关’] = np.where((条件1) & (条件2), ‘是’,‘否’)
4、删除重复值df = df.drop_duplicates(keep=‘first’) # 删除重复值
5、重命名列名 方法1list_17 = temp_17.columns.values.tolist() 取出列名,转为列表
temp_18.set_axis(list_17, axis=‘columns’, inplace=True) 用列表命名列
ni.rename(columns={“干扰 0”: “0”,
“干扰1”: “1”,
“干扰2”: “2”,
“干扰3”: “3”,
“干扰4”: “4”}, inplace=True)
km.rename(columns={‘名称’: ‘小区’, ‘干扰’:‘KM内干扰’}, inplace=True)
6、组合名字temp[‘id’] = temp[‘NAME’].map(str) + “_” + temp[‘标识’].map(str) # NAME与ID组合
7、拼接数据(V)result2 = pd.merge(result1, temp, left_on=‘du_id’, right_on=‘_id’,
how=‘left’, suffixes=[‘’, ‘_SE’])
temp_o = pd.read_csv(‘xxx.csv’, encoding=‘gbk’, low_memory=False)
mm.to_csv(‘xxx.csv’ , index=False, encoding=‘utf_8_sig’)
9、读写excelinfo = pd.read_excel(‘xxx.xlsx’)
info = pd.read_excel(‘xxx.xlsx’, sheetname=‘xxx’)
info.to_excel( ‘project_cn.xlsx’,sheet_name = “L”, index=False)
10、替换mm.replace([888], [‘’], inplace=True) # 用空值 替换888值
mm[‘干扰’].replace([‘NIL’, ‘’], [-120, -120], inplace = True) # 用-120替换NIL和空值
11、查找startwith,endwith
mm = [name for name in os.listdir(self.path_result) if name.startswith(‘基本信息’)]
12、按条件删除 单条件ni.drop(ni[(ni[‘平均’].str.contains(‘NIL’) == True)].index, inplace=True)
多条件ni.drop(ni[(ni[‘’].str.contains(‘NIL’) == True) &
(ni[‘0’].str.contains(‘NIL’) == True) &
(ni[‘1’].str.contains(‘NIL’) == True) &
(ni[‘2’].str.contains(‘NIL’) == True) &
(ni[‘3’].str.contains(‘NIL’) == True) &
(ni[‘4’].str.contains(‘NIL’) == True) &
(ni[‘全部’].str.contains(‘NIL’) == True)].index, inplace=True)



