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

I wanted new_df data frame to only have data of the employee who have login but not log out.我希望 new_df 数据框仅包含已登录但未注销的员工的数据。 In attached excel data sheet if counter = -1 then i am assuming logout and if counter = 1 i am assuming login link for the sheet "https://drive.google.com/file/d/1E9hivsHzc9lc_IQG0mWf36fc8F4HgPDm/view?usp=sharing"在随附的 excel 数据表中,如果计数器 = -1,那么我假设注销,如果计数器 = 1,我假设工作表的登录链接“https://drive.google.com/file/d/1E9hivsHzc9lc_IQG0mWf36fc8F4HgPDm/view?usp=sharing "

I don't have the filter for the time, but here's a way to get the records for employees that don't have a counter record = -1我暂时没有过滤器,但这里有一种方法可以获取没有计数器记录 = -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.

相关问题 需要为 Panda 数据框打印一个新列 - Need to print a new column for Panda data frame 从数据框中提取行并使其成为新数据框并将其索引更改为列值 - Extract row from a data frame and make it a new data frame and change its index as like column value 如何通过一列的值计数对熊猫数据框进行排序? - How to sort a pandas data frame by value counts of a column? 从与来自不同数据框的列索引值相对应的列表中创建一个新的计数数据框 - Create a new data frame of counts from a list corresponding to column index values from a different data frame 根据条件从数据框中的现有列创建新列 - Creating a new column from existing column in the data frame based on the criteria 当现有列'B'的连续5个单元格值为python中数据框的空白时,为新列'A'分配一个标志 - Assigning a flag to a new column 'A' when continuously 5 cells value of existing column 'B' is blank of a data frame in python Pandas:value_counts 进入数据帧 - Pandas: value_counts into a data frame 熊猫:将新列添加到现有数据框以进行分组 - Pandas: adding new column to existing Data Frame for grouping purposes 使用 Pandas 从现有列创建新列到数据框 - Create a new column to data frame from existing columns using Pandas 基于现有列在 pandas 数据框中创建新列 - Create new columns in pandas data frame based on existing column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM