group

Replace column values using another pandas dataframe mapping

Replace column values using another pandas dataframe mapping Question: Imagine I have the following dirty data of employee information of their contracts across countries (df1): ID Country Name Job Date Grade 1 CZ John Office 2021-01-01 Senior 1 SK John . 2021-01-01 Assistant 2 AE Peter Carpinter 2000-05-03 3 PE Marcia Cleaner 1989-11-11 ERROR! 3 …

Total answers: 1

How to select user_id rows pandas

How to select user_id rows pandas Question: How can I calculate the first visited date and the last visited date before an order was placed by the user? USER ID TYPE DATE 1 Visited September 14, 2020 1 Visited October 4, 2020 1 Visited October 24, 2020 1 Ordered November 1, 2020 2 Visited September …

Total answers: 2

Finding all directed paths in networkx and saving them as a dataframe

Finding all directed paths in networkx and saving them as a dataframe Question: I need to find all directed paths in a network as shown in the sample, and save the directed paths in a new dataframe. Sample: import pandas as pd import networkx as nx import matplotlib.pyplot as plt sample_dict = { ‘target’: [‘A’, …

Total answers: 2

in python sort and group by common elements in a list

in python sort and group by common elements in a list Question: I will try to express myself clearly. Would anyone know how to order elements with common values in a list? I made a drawing to explain it better. I have a list with several letters and their two number. ev=((‘A’,(1,2)), (‘M’,(0,40)),(‘S’,(17,32)),(‘Z’,(2,7)),(‘K’,(7,12)),(‘U’,(40,18)),(‘R’,(32,5)),(‘V’,(28,47)),(‘X’,(5,28))) and after …

Total answers: 1

Merge two Dataframe without duplicate rows pandas

Merge two Dataframe without duplicate rows pandas Question: We have problem in merge two different Pandas data frame, using the merge method it duplicate the rows with the same ID We have two different DF in Pandas: DF1: ID Gender 0 1 Male 1 2 Female 2 3 Female DF2 ID Vote 0 1 30 …

Total answers: 2

Group by timestamp and get mean Dataframe

Group by timestamp and get mean Dataframe Question: I generate for each week as csv file. The weeks are then merged into one. The merged CSV with the Dataframe looks like this: machineId | id | mean | min | max machine1 | 2 | 00:00:03.47 | 00:00:00.02 | 00:00:06.11 machine1 | 1 | 00:00:01.30 …

Total answers: 1

How to group lists according to at least one element in common in Python?

How to group lists according to at least one element in common in Python? Question: I have a list of lists and I want to group them according to at least one element in common for at least two sublists of a group. Therefore, each sublist in a specific group doesn’t need to have an …

Total answers: 1

AttributeError: 'Group' object has no attribute 'collide' Pygame

AttributeError: 'Group' object has no attribute 'collide' Pygame Question: I’m creating a basic simulation in pygame and my object (an amoeba represented by a green square on the screen) has two methods. My update method is running fine, but the collide method is giving my an attribute error. By the way, since I have added …

Total answers: 1

Pandas: start a new group on every non-NA value

Pandas: start a new group on every non-NA value Question: I am looking for a method to create an array of numbers to label groups, based on the value of the ‘number’ column. If it’s possible? With this abbreviated example DF: number = [nan,nan,1,nan,nan,nan,2,nan,nan,3,nan,nan,nan,nan,nan,4,nan,nan] df = pd.DataFrame(columns=[‘number’]) df = pd.DataFrame.assign(df, number=number) Ideally I would like …

Total answers: 2