iteration

Add multiple columns and values to a pandas dataframe

Add multiple columns and values to a pandas dataframe Question: I will ask my question with a small dataframe, but the real one is 1000s of lines. ID Name #Required 123 New York 5 234 Boston 6 345 Miami 2 345 Dallas 7 I need the to the number of columns equals to the max …

Total answers: 2

Iteration in a dictionary with lists as values

Iteration in a dictionary with lists as values Question: A dictionary with lists as values and ascending dates as keys, that I want to understand how many times M in the total past times P, cover some of the current numbers. For example, for L19981120: [2, 3, 5]: 2 numbers in the [2, 3, 5], …

Total answers: 2

How to increase the value of a new column after 'N' number of rows

How to increase the value of a new column after 'N' number of rows Question: I have a Dataframe which consists a thousand rows, and I want to add 1 to particular column "Level" after every 100 rows. I am sharing a small self created sample of how the data looks like: import pandas as …

Total answers: 2

Finding total amount of paths in a triangle grid (iterative without recursion)

Finding total amount of paths in a triangle grid (iterative without recursion) Question: i have a given a triangle grid: Triangle For every point (i,j) with i+j being even: Given recursive function Now i need to write a iterative function that finds all possible paths from (0,0) to the point (2n,0) given that n ∈ …

Total answers: 3

Implementing the Fibonacci sequence for the last n elements: The nBonacci sequence

Implementing the Fibonacci sequence for the last n elements: The nBonacci sequence Question: I was curious about how I can implement the Fibonacci sequence for summing the last n elements instead of just the last 2. So I was thinking about implementing a function nBonacci(n,m) where n is the number of last elements we gotta …

Total answers: 3

Why are these for loops running incredibly slow in python?

Why are these for loops running incredibly slow in python? Question: I’m working on a short programme which will create a 2d array for the Tabula Recta. However, I am finding it is running incredibly slow, especially the further down the for loop I get. What is the reason for this, as I’ve never had …

Total answers: 1

Pandas; Trying to split a string in a column with | , and then list all strings, removing all duplicates

Pandas; Trying to split a string in a column with | , and then list all strings, removing all duplicates Question: I’m working on a data frame for a made up TV show. In this dataframe, are columns: "Season","EpisodeTitle","About","Ratings","Votes","Viewership","Duration","Date","GuestStars",Director","Writers", With rows listed as ascending numerical values. In this data frame, my problem relates to two …

Total answers: 1

Delete row if next row has the same first value, python

Delete row if next row has the same first value, python Question: I have an array that looks like this: data([0.000, 1], [0.0025, 2], [0.0025, 3], [0.005, 5]) I need to delete [0.0025, 3], because it has the same first value as the one before. I have tried: for i in data: if data[i, 0] …

Total answers: 1