簡體   English   中英

需要在現有數據框的一列中創建僅具有奇數個值的新數據框

[英]Need to make new data frame with only odd counts of a value in a column of existing data frame

import plotly.express as px
import plotly.graph_objects as go
import pandas as pd

df = pd.read_excel ('the sample sheet i have attached')

indexNames = df[ (df['counter'] != -1) & (df['counter'] != 1) & (df['id'] >= "Fri Jul 10 19:33:12 GMT+05:30 2020")  ].index
dff.drop(indexNames , inplace=True)

v = df.employee_id.value_counts()

new_df= df[df.employee_id.isin(v.index[v.eq(1)])]
new_df

我希望 new_df 數據框僅包含已登錄但未注銷的員工的數據。 在隨附的 excel 數據表中,如果計數器 = -1,那么我假設注銷,如果計數器 = 1,我假設工作表的登錄鏈接“https://drive.google.com/file/d/1E9hivsHzc9lc_IQG0mWf36fc8F4HgPDm/view?usp=sharing "

我暫時沒有過濾器,但這里有一種方法可以獲取沒有計數器記錄 = -1 的員工的記錄

import pandas as pd
logins = {'EmployeeId': [22, 22, 22, 22, 67, 67, 67],
    'Counter': [1, 2, 3, -1, 1, 2, 3] }

df = pd.DataFrame(logins)
df2 = df.loc[df['Counter'] == -1]
print(df[~df['EmployeeId'].isin(df2['EmployeeId'])])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM