繁体   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