pandas

How to check if a value in one dataframe is present in keys in the other dataframe

主宰稳场 提交于 2021-02-13 17:38:08
问题 I have two dataframes: df_1: Letters Boolean a Nan b Nan c Nan df_2: a b d 2.7 1.2 3.6 1 2 3 How do I check if df_1['letters'] is present in df_2.keys(). If it is present, I want boolean to take the value 'x': Something like: Letters Boolean a x b x c Nan I tried using this code: for x in df_1['letters']: if x in df_2.keys(): df_1['Boolean']='x' 回答1: Use numpy.where with isin: df1['Boolean'] = np.where(df1['Letters'].isin(df2.columns), 'x', np.nan) 回答2: You need : df1['Boolean']=df1.Letters

自己动手写一个印钞机 第六章

纵然是瞬间 提交于 2021-02-13 16:40:06
作者:阿布🐶 未经本人允许禁止转载 ipython notebook git版本 目录章节地址: 自己动手写一个印钞机 第一章 自己动手写一个印钞机 第二章 自己动手写一个印钞机 第三章 自己动手写一个印钞机 第四章 自己动手写一个印钞机 第五章 自己动手写一个印钞机 第六章 自己动手写一个印钞机 第七章 简书目录章节地址: 自己动手写一个印钞机 第一章 自己动手写一个印钞机 第二章 自己动手写一个印钞机 第三章 自己动手写一个印钞机 第四章 自己动手写一个印钞机 第五章 自己动手写一个印钞机 第六章 自己动手写一个印钞机 第七章 自己动手写一个印钞机 附录章 股票量化专题地址,请关注,谢谢! 非均衡胜负收益带来的必然非均衡胜负比例,目标由因子的能力解决一部分,模式识别提升关键的一部分 上一章构造了 3个主裁和一个辅助裁判,这一章开始构建边裁及裁判的最优参数选择 fn = ZEnv.g_project_root + '/data/cache/orders_pd_ump_hit_predict_abu' key = 'orders_pd_ump_hit_predict_abu' orders_pd_ump = ZCommonUtil.load_hdf5(fn, key) orders_pd_ump.shape # out (47374, 39) UmpEdge 边裁 import

自己动手写一个印钞机 第三章

那年仲夏 提交于 2021-02-13 16:39:51
作者:阿布🐶 未经本人允许禁止转载 ipython notebook git版本 目录章节地址: 自己动手写一个印钞机 第一章 自己动手写一个印钞机 第二章 自己动手写一个印钞机 第三章 自己动手写一个印钞机 第四章 自己动手写一个印钞机 第五章 自己动手写一个印钞机 第六章 自己动手写一个印钞机 第七章 简书目录章节地址: 自己动手写一个印钞机 第一章 自己动手写一个印钞机 第二章 自己动手写一个印钞机 第三章 自己动手写一个印钞机 第四章 自己动手写一个印钞机 第五章 自己动手写一个印钞机 第六章 自己动手写一个印钞机 第七章 自己动手写一个印钞机 附录章 股票量化专题地址,请关注,谢谢! 非均衡胜负收益带来的必然非均衡胜负比例,目标由因子的能力解决一部分,模式识别提升关键的一部分 上一章使用机器学习的方法,想要提取特征,指导交易,提高胜率,但是发现,除了最后那种把交易结果分成100份的方式外,其它机器学习方法基本都是瞎猜,是不是使用深度学习就能解决问题呢?本章主要通过使用卷积神经网络模型alex_net, 与google_lenet对stock进行模式识别 加载缓存交易数据 # 从之前跑的结果hdf5中加载缓存 from MlFiterDegPd import MlFiterDegPdClass orders_pd_train_snap = ZCommonUtil.load

自己动手写一个印钞机 第二章

房东的猫 提交于 2021-02-13 16:39:34
作者:阿布🐶 未经本人允许禁止转载 ipython notebook git版本 目录章节地址: 自己动手写一个印钞机 第一章 自己动手写一个印钞机 第二章 自己动手写一个印钞机 第三章 自己动手写一个印钞机 第四章 自己动手写一个印钞机 第五章 自己动手写一个印钞机 第六章 自己动手写一个印钞机 第七章 简书目录章节地址: 自己动手写一个印钞机 第一章 自己动手写一个印钞机 第二章 自己动手写一个印钞机 第三章 自己动手写一个印钞机 第四章 自己动手写一个印钞机 第五章 自己动手写一个印钞机 第六章 自己动手写一个印钞机 第七章 自己动手写一个印钞机 附录章 股票量化专题地址,请关注,谢谢! 非均衡胜负收益带来的必然非均衡胜负比例,目标由因子的能力解决一部分,模式识别提升关键的一部分 本章开始说文章的核心了, 模式识别提升关键的一部分 本章的内容主要是通过机器学习如svm,随机森林等对stock模式识别的初步探索,俗称罪恶的第一步,但还是要坚定的卖出,毕竟目标是印钞机 下面运行因子对多年数据进行回测,模式识别中基本的需求就是生成训练集数据与测试集数据,对训练集的数据抽取特质,总结规律,在测试集上指导交易,与没有指导交易的测试集进行比对,查看效果。 BuyGoldenFactor.g_enable_filter_ml = True # 回测因子的历史且结果集加入机器学习需要的数据

Merge values of a dataframe where other columns match

旧街凉风 提交于 2021-02-11 18:24:48
问题 I have a dataframe storing a date, car_brand, color and a city: date car_brand color city "2020-01-01" porsche red paris "2020-01-02" prosche red paris "2020-01-03" porsche red london "2020-01-04" porsche red paris "2020-01-05" porsche red london "2020-01-01" audi blue munich "2020-01-02" audi red munich "2020-01-03" audi red london "2020-01-04" audi red london "2020-01-05" audi red london I now want to create from that a dataframe in the following way: Merge rows together where for

Normalizing json list as values

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-11 18:22:39
问题 I have a problem to normalize a json, I can't find a solution in all the documentation I found. my json: {'id': 790005, 'company_id': 700025, 'owner_id': {'id': 11300075, 'name': '*** Alves', 'email': '*****.alves@***rs.com.br', 'has_pic': 0, 'pic_hash': None, 'active_flag': True, 'value': 100075}, 'org_id': None, 'name': 'V****or - 37****376 - Jo****ctor', 'first_name': 'Vi****r', 'last_name': '37****76 - - Jo****or', 'open_deals_count': 0, 'related_open_deals_count': 0, 'closed_deals_count'

How can I keep the rows of a pandas data frame that match a particular condition using value_counts() on multiple columns

折月煮酒 提交于 2021-02-11 18:01:53
问题 I would like to get rid of those rows where a particular value occurs only once in a column, considering 3 columns. That is, for feature: text: if value_counts() == 1, then eliminate those rows, or just keep when value_counts() > 1 next_word: if value_counts() == 1, then eliminate those rows, or just keep when value_counts() > 1. In this case, just work with the already processed (just kept the rows that the column 'text' contains values showing up more than once) previous_word: if value

How can I keep the rows of a pandas data frame that match a particular condition using value_counts() on multiple columns

蹲街弑〆低调 提交于 2021-02-11 18:01:05
问题 I would like to get rid of those rows where a particular value occurs only once in a column, considering 3 columns. That is, for feature: text: if value_counts() == 1, then eliminate those rows, or just keep when value_counts() > 1 next_word: if value_counts() == 1, then eliminate those rows, or just keep when value_counts() > 1. In this case, just work with the already processed (just kept the rows that the column 'text' contains values showing up more than once) previous_word: if value

Converting a Datetime column to a DatetimeIndex in pandas

混江龙づ霸主 提交于 2021-02-11 17:57:53
问题 There are so many questions that revolve around converting dates to a datetimeindex. I personally need a datetimeindex to work with the Calmap package that requires the datetimeindex. After following many stackoverflow guides, I haven't been able to change my date fields to a datetimeindex. Here are the following steps I took. import numpy as np import pandas as pd ##I also attempted to add parse_dates=["Date'] and Index["Date"] to the pd.read_csv() main_data = pd.read_csv('newoutput2.csv',

Converting a Datetime column to a DatetimeIndex in pandas

心不动则不痛 提交于 2021-02-11 17:57:37
问题 There are so many questions that revolve around converting dates to a datetimeindex. I personally need a datetimeindex to work with the Calmap package that requires the datetimeindex. After following many stackoverflow guides, I haven't been able to change my date fields to a datetimeindex. Here are the following steps I took. import numpy as np import pandas as pd ##I also attempted to add parse_dates=["Date'] and Index["Date"] to the pd.read_csv() main_data = pd.read_csv('newoutput2.csv',