Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望ref函数中参数n支持序列值 #54

Open
hotwind2015 opened this issue Dec 1, 2023 · 5 comments
Open

希望ref函数中参数n支持序列值 #54

hotwind2015 opened this issue Dec 1, 2023 · 5 comments

Comments

@hotwind2015
Copy link

No description provided.

@kevinyang72
Copy link

I'm facing the same issue. Please add this support.

@hotwind2015
Copy link
Author

hotwind2015 commented Jan 29, 2024

I'm facing the same issue. Please add this support.
试试下面的这个

def REF(S, N=1):  # 对序列整体下移动N,返回序列(shift后会产生NAN)
    if isinstance(N, (int, float)):
        return pd.Series(S).shift(N).values
    else:
        res = np.repeat(np.nan, len(S))
        for i in range(len(S)):
            if (not np.isnan(N[i])):
                res[i] = S[N[i]]
        return res

@kevinyang72
Copy link

Does not seem working for me.
How the shift works here with "res[i] = S[N[i]]"?

@hotwind2015
Copy link
Author

Does not seem working for me. How the shift works here with "res[i] = S[N[i]]"?

try this

def REF(S, N=1):  # 对序列整体下移动N,返回序列(shift后会产生NAN)
    if isinstance(N, (int, float)):
        return pd.Series(S).shift(N).values
    else:
        res = np.repeat(np.nan, len(S))
        for i in range(len(S)):
            if (not np.isnan(N[i])):
                res[i] = pd.Series(S).shift(N[i])[i]
        return res

S=[0,1,2,3,4,5]
N = [1,2,2,3,3,1]
res = REF(S,N)
print(res)

# will print [nan nan  0.  0.  1.  4.]

@kevinyang72
Copy link

kevinyang72 commented Jan 30, 2024

Excellent! It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants