I am a noob CS student trying to get a program running using if/else and while for. I am using the debugger and stepping through the code. I can see that my “current_min” starts at 0 by default and doesn’t change. I know I should grab the user input to define max/min, but when I try to put i…
Tag: python
When does a HashTable / Python dict stop probing?
In Java I’m building a datastructure that is supposed to resemble dictionaries in Python. (As far as I understand this is called a “HashTable” in java context.) I have read the following Python documentation in order to arrive at the probing function (as I wished to prevent using linear prob…
How can I create a new pandas DataFrame out of an existing one applying a function to every column without a for loop?
A simplified script I have now working is as follows: How can I get the same result (a one row dataframe) with a simpler, more efficient code? Answer Try with apply:
Create a dictionary whose keys are month names and values are no. of days in the corresponding month. #program stack
please correct the code. Create a dictionary whose keys are month names and values are no. of days in the corresponding month. WAP with separate user defined functions to implement the following operations. (i)push only those names on the stack whose no. of days are 31. (ii) pop and display the content of the…
All cells getting updated in pandas df using loc
So I create an empty pandas df, where I initialize all the cell values to empty lists, except the diagonals, which are set to math.inf The indexes are the start position, and the column headers are the end position I want to get the start and end positions, and the difference between the days to get from star…
Why isn’t my re.sub finding all instances using my regex?
I’m using Python 3.10 on Windows 10 and trying the search below: If I use just “JohnnyB Cool”, the “B” gets a space before it. Why isn’t the “JohnnyB” substituted in the first search? I’ve also tried: To be clear, I want the final answer to be, Johnny B Co…
How does rsuffix and lsuffix work while joining multiple dataframes?
I have written the following code however I am unable to understand how to name the rsuffix and lsuffix parameters All my dfs have same column names example: When I am printing dfs_list[2].reset_index() I do get my expected output but I am unable to comprehend the suffix names. How do we define it? output: Ca…
Cannot Change Individual Elements in an Array
I am trying to make a tic-tac-toe game, and I currently have a 3×3 tiled board grid to represent the game. When a user clicks a square, the program sets board[x][y] to 1. board = [[[0, 0, 0], [0, 0, 0], [0, 0, 0]] Unfortunately, whenever I click a tile, it seems to ignore whatever x value I put; every
Error while concatenating date and time columns in pandas
I have a data frame with the following properties: Date column has values as format : 2021-11-28 00:00:00 and Time column has values as format: 08:15:12.476000. I am trying to create a DateTime column with the following code (basically tried most of the available pandas’ methods like to_datetime, to_tim…
split a string representation with ranges into a list of dates
I have this pandas dataframe column with timeranges (02.07.2021 – 07.07.2021 ) and single days (04.08.2021) as a list. Dates ‘02.07.2021 – 07.07.2021 , 04.08.2021, 19.06.2021 – 21.06.2021’ ‘13.02.2021 – 15.02.2021 , 03.03.2021 ‘ NaN NaN I want this: Dates 02.07.…