python - 需要在现有数据框的一列中创建仅具有奇数个值的新数据框
问题描述
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'])])
推荐阅读
- reactjs - 如何显示用户特定数据?
- python - 使用 python selenium 下载
- ios - 如何在 Swift 4 中的 WKWebView 中加载网页之前删除白屏?
- python - Django自动注销未在数据库中更新
- asterisk - 在接听电话前发送脉冲
- android - 如何通过 Android 中的 AccessibilityService 以编程方式禁用移动设备的最近按钮
- javascript - chart.js 标签颜色根据值变化
- haskell - Haskell 解压折叠
- javascript - 使用 npm 的 request 包,你应该如何传递最初保存在文件中的数据?
- linux-kernel - “kauditd_printk_skb”在linux内核中的作用