I am working on a timetable system and need all the free slots (where the student has no lectures). Right now it prints the entire timetable out. I just need to store all the free slots somewhere. They are showing up as “NaN” on the time table. here is my code. Expected output would be all the fre…
Tag: dataframe
Deleting consecutive rows in a pandas dataframe with the same value
How can I delete only the three consecutive rows in a pandas dataframe that have the same value (in the example below, this would be the integer “4”). Consider the following code: I would like to get the following result as output with the three consecutive rows containing the value “4”…
How can convert struct column timestamp with start and end into normal pythonic stamp column?
I have a time-series pivot table with struct timestamp column including start and end of time frame of records as follow: Since later I will use timestamps as the index for time-series analysis, I need to convert it into timestamps with just end/start. I have tried to find the solution using regex maybe unsuc…
How to reverse a pandas series
I have a pandas series that must be flipped upside-down before I concatenate it to the main DataFrame. I can easily flip it with myseries = myseries.iloc[::-1] But when I attach it to the main DataFrame, it attaches the default series and not the flipped version. Why doesn’t the flipped series stay in p…
Python Dataframe – only keep oldest records from each month
I have a Pandas Dataframe with a date column. I want to only have the oldest records for each month and remove any records that came before. There will be duplicates and I want to keep them. I also need a new column with only the month and year. Input Provider date Apple 01/01/2022 Apple 05/01/2022 Apple 20/0…
Dropping duplicate rows ignoring case (lowercase or Uppercase)
I have a data frame with one column (col). I’m trying to remove duplicate records regardless of lowercase or Uppercase, for example output: Expected Output: How can this Dropping be done regardless of case-insensitively? Answer You could use: output:
Efficient chaining of boolean indexers in pandas DataFrames
I am trying to very efficiently chain a variable amount of boolean pandas Series, to be used as a filter on a DataFrame through boolean indexing. Normally when dealing with multiple boolean conditions, one chains them like this but this becomes a problem with a variable amount of conditions. I have tried out …
Appending row to dataframe with concat()
I have defined an empty data frame with and want to append rows in a for loop like this: But I get this error If I use df = df.append(row, ignore_index=True), it works but it seems that append is deprecated. So, I want to use concat(). How can I fix that? Answer You can transform your dict in pandas DataFrame
In Pandas, how to group by column name and condition met, while joining the cells that met the condition in a single cell
I am having a hard time knowing how to even formulate this question, but this is what I am trying to accomplish: I have a pandas datatable with thousands of rows that look like this: id text value1 value2 1 These are the True False 2 Values of “value1” True False 3 While these others False True 4 …
How to find the intersection between two columns from two different dataframes
I’m trying to compare two different columns from two different DataFrames. When I call: The output should be just “www.google.com” but instead this is the output I get. Completely Stuck! Thank you for your help in advance! Answer The standard way to do this in pandas is an inner merge (defau…