Структура данных – перенос идентификаторов на следующие даты в PythonPython

Программы на Python
Гость
Структура данных – перенос идентификаторов на следующие даты в Python

Сообщение Гость »


I have a dataset where I have Date and ID.


Изображение

Код: Выделить всё

Created the dataset using the following code import pandas as pd # Function to generate the specified dataset def generate_dataset():     data = {         'Date': ['09-03-2024']*7 + ['10-03-2024']*4,         'ID': [f'ID_{i}' for i in range(1, 12)]     }     df = pd.DataFrame(data)     return df # Generate the dataset dataset = generate_dataset() # Print the dataset print(dataset) 
I need a function which can take in a datset like this along with max_number of IDs possible per day. It should move the additional IDs to the next date. And do this for all unique dates. So the output should look something like this, if the max IDs per date is 2.


Изображение



Источник: https://stackoverflow.com/questions/781 ... -in-python

Вернуться в «Python»