随笔分类 -  pandas

摘要:df.insert(0, 'New_ID', range(1, 1+ len(df))) 阅读全文
posted @ 2022-03-11 15:00 hifalee 阅读(1647) 评论(0) 推荐(0) 编辑
摘要:df[['c', 'd']] = df.apply(lambda x: func_main(x['a'], x['b']), axis=1, result_type='expand') 阅读全文
posted @ 2022-02-24 18:20 hifalee 阅读(69) 评论(0) 推荐(0) 编辑
摘要:df = pd.read_csv(file_name ,converters={col_name: str}) 阅读全文
posted @ 2022-02-08 10:47 hifalee 阅读(306) 评论(0) 推荐(0) 编辑
摘要:df.sort_values("salary",inplace=True)反序 df.sort_values(by="salary",ascending=False) 阅读全文
posted @ 2021-11-02 10:26 hifalee 阅读(361) 评论(0) 推荐(0) 编辑
摘要:df = df.filter(["entryName","classifyId"], axis=1) df = df.drop('B', axis=1) 阅读全文
posted @ 2021-10-12 14:46 hifalee 阅读(303) 评论(0) 推荐(0) 编辑
摘要: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= 阅读全文
posted @ 2021-01-28 15:44 hifalee 阅读(62) 评论(0) 推荐(0) 编辑
摘要:df = pd.read_csv(r_f1) df['machine_Id'] = df['UserId']+df['knowledge_encoding'] df.rename(columns={"UserId": "old_UserId","machine_Id":"UserId"},inpla 阅读全文
posted @ 2021-01-27 16:30 hifalee 阅读(472) 评论(0) 推荐(0) 编辑
摘要: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) # 数据有三列,列 阅读全文
posted @ 2020-11-26 15:56 hifalee 阅读(120) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2020-11-26 11:27 hifalee 阅读(319) 评论(0) 推荐(0) 编辑
摘要:读取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() 读取 阅读全文
posted @ 2020-11-25 15:12 hifalee 阅读(73) 评论(0) 推荐(0) 编辑
摘要:通过list写入excel list1 = [['张三','男','未婚',20],['李四','男','已婚',28],['小红','女','未婚',18],['小芳','女','已婚',25]] output = open('data.xls','w',encoding='gbk') outpu 阅读全文
posted @ 2020-11-25 15:03 hifalee 阅读(768) 评论(0) 推荐(0) 编辑
摘要:df.groupby(['opponent']).game_id.nunique()= for index,group in df.groupby(df['opponent'])['game_id']: print(index) print(len(set(list(group)))) 阅读全文
posted @ 2020-11-25 08:58 hifalee 阅读(75) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示