Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

python - 将DataFrame分成两个DataFrame并过滤这两个DataFrame以具有相同的尺寸(Splitting DataFrame into two DataFrames and filter these two DataFrames in order to have the same dimensions)

i have the following problem and had an idea to solve it, but it didn't worked: I have the data on DAX Call and Put Options for every trading day in a month .

(我遇到以下问题,并且有解决此问题的想法,但没有成功:我每个月的每个交易日都有 DAX看涨期权和看跌期权的数据。)

After transforming and some calculations I have the following DataFrame: DaxOpt .

(经过转换和一些计算之后,我得到了以下DataFrame: DaxOpt 。)

The goal is now to get rid of every row (either Call or Put Option) which does not have the respective pair.

(现在的目标是摆脱没有相应对的每一行(看涨期权或看跌期权)。)

With pair I mean a Call and Put Option with the same 'EXERCISE_PRICE' and 'TAU', where 'TAU' = the time to maturity in years.

(一对是指具有相同“ EXERCISE_PRICE”和“ TAU”的看涨期权和看跌期权,其中“ TAU” =到期时间(以年为单位)。)

The red boxes in the picture are examples for a pair.

(图片中的红色框是一对的示例。)

So either having a DataFrame with only the pairs or having two DataFrames with Call and Put Options where the rows are the respective pairs.

(因此,要么具有仅具有一对的DataFrame,要么具有两个具有“调用”和“放置选项”的DataFrame,其中行是各自的对。)

My idea was creating two new DataFrames one which contains only the Call Options and the other the Put Options, sort them after 'TAU' and 'EXERCISE_PRICE' and working my way through with pandas isin function, in order to get rid of the Call or Put Options which do not have the respective pair.

(我的想法是创建两个新的DataFrame,其中一个仅包含调用选项,另一个包含Put选项,将它们排序在“ TAU”和“ EXERCISE_PRICE”之后,并通过pandas isin函数进行操作,以摆脱Call或放置没有相应货币对的期权。)

DaxOptCall = DaxOpt[DaxOpt.CALL_PUT_FLAG == 'C']

(DaxOptCall = DaxOpt [DaxOpt.CALL_PUT_FLAG =='C'])

DaxOptPut = DaxOpt[DaxOpt.CALL_PUT_FLAG == 'P']

(DaxOptPut = DaxOpt [DaxOpt.CALL_PUT_FLAG =='P'])

The problem is that the DaxOptCall and DaxOptPut have different dimensions, so isin function is not applicable.

(问题在于DaxOptCall和DaxOptPut具有不同的尺寸,因此isin函数不适用。)

I am trying to find the most efficient way, since the data I am using now is just a fraction from the real data.

(我正在尝试找到最有效的方法,因为我现在使用的数据只是真实数据的一小部分。)

Would appreciate any help or idea.

(将不胜感激任何帮助或想法。)


  ask by C0deP0ntage translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...