随笔分类 - pandas
摘要:df.insert(0, 'New_ID', range(1, 1+ len(df)))
阅读全文
摘要:df[['c', 'd']] = df.apply(lambda x: func_main(x['a'], x['b']), axis=1, result_type='expand')
阅读全文
摘要:df = pd.read_csv(file_name ,converters={col_name: str})
阅读全文
摘要:df.sort_values("salary",inplace=True)反序 df.sort_values(by="salary",ascending=False)
阅读全文
摘要:df = df.filter(["entryName","classifyId"], axis=1) df = df.drop('B', axis=1)
阅读全文
摘要:user_list = df['UserId'].value_counts() user_list = user_list[user_list>=5].index.tolist() df = df[df['UserId'].isin(user_list)] df.to_csv(w_f1,index=
阅读全文
摘要:df = pd.read_csv(r_f1) df['machine_Id'] = df['UserId']+df['knowledge_encoding'] df.rename(columns={"UserId": "old_UserId","machine_Id":"UserId"},inpla
阅读全文
摘要:import pandas as pd #写入 list = [[1, 2, 3], [4, 5, 6], [7, 9, 9]] name = ['one', 'two', 'three'] test = pd.DataFrame(columns=name, data=list) # 数据有三列,列
阅读全文
摘要:csv.read with open("test.csv", "r", encoding = "utf-8") as f: reader = csv.reader(f) rows = [row for row in reader] csv.write with open(file, 'w', new
阅读全文
摘要:读取csv文件 data = pd.read_csv(f1,nrows =20) s = data.loc[:, :] s = s.loc[:, ['machine_id', 'question_id', 'answer_right']] s = s.values s = s.tolist() 读取
阅读全文
摘要:通过list写入excel list1 = [['张三','男','未婚',20],['李四','男','已婚',28],['小红','女','未婚',18],['小芳','女','已婚',25]] output = open('data.xls','w',encoding='gbk') outpu
阅读全文
摘要:df.groupby(['opponent']).game_id.nunique()= for index,group in df.groupby(df['opponent'])['game_id']: print(index) print(len(set(list(group))))
阅读全文