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

Pandas tricks #7

Open
chengjun opened this issue Aug 9, 2020 · 1 comment
Open

Pandas tricks #7

chengjun opened this issue Aug 9, 2020 · 1 comment

Comments

@chengjun
Copy link
Member

chengjun commented Aug 9, 2020

d = pd.DataFrame({
    "Disease":["D{}".format(i) for i in range(1,9)],
    "Gene1":[0,0,0,24,0,0,0,4],
    "Gene2":[0,0,17,0,0,32,0,0],
    "Gene3":[25,0,0,0,0,0,0,0],
    "Gene4":[0,0,16,0,0,11,0,0]})

d

image

row_index = d[d['Disease'].isin(['D1', 'D2'])].index
col_names = ['Gene1', 'Gene2']
d.loc[row_index, col_names] +=1
d

image

@chengjun
Copy link
Member Author

chengjun commented Aug 9, 2020

def AdjustNeighborCounts(row, race_of_mover, delta):
    # row = 3
    # race_of_mover = "darkred"
    # delta = 1
    curr_x = int(row) % side
    curr_y = np.floor(int(row)/side)
    condition1 = df['x'].isin(range(int(curr_x) - depth, int(curr_x) + depth+1))
    condition2 = df['y'].isin(range(int(curr_y) - depth, int(curr_y) + depth+1))
    condition3 = ~ ((df['x']==curr_x) & (df['y']==curr_y))
    row_index = df[(condition1) & (condition2) & (condition3)].index
    col_index = [race_of_mover, "num.neighbors"]
    df.loc[row_index, col_index]+=delta

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

1 participant