I have a dataframe which is the result of a concatenation of dataframe. I use “keys= ” option for the title of each blocks when I export in Excel. And now I want define the ID2 as an index with ID. (For have a multindex) I tried to use .resetindex, but it didn’t work like I want. I have: I
Tag: pandas
how to delete rows from excel who has red background color using python
read_file.style.apply(lambda x: [ ‘background-color:%s’ % ‘red’ if x < y else ‘background-color :%s’ % ‘green’ for x in read_file.language], axis=0 ,inplace=True) print(“done”) read_file.to_excel(‘coloured.xlsx’,engine=’openpyxl&…
Delete the rows that have the same value in the columns Dataframe
I have a dataframe like this : origin destination germany germany germany italy germany spain USA USA USA spain Argentina Argentina Argentina Brazil and I want to filter the routes that are within the same country, that is, I want to obtain the following dataframe : origin destination germany italy germany sp…
A code to find out the count of females and males in a column using python
I want an output in a table as shown below: Answer Example inspired by this article This prints You can read more about value_counts() here.
How am I able to replace duplicates in a dataframe column in python?
say my column is something like this: I would like to drop the duplicate elements in the column and replace them with NAN or 0 so it would end up with something like: I am completely unsure of the logic I can use to do this, I think I would forward fill up until the next change in signal with
Pandas: Plotting / annotating from DataFrame
There is this boring dataframe with stock data I have: Then I am plotting the prices So far so good… Then I’d like to show a marker on the chart if there was buy (green) or sell (red) on that day. It’s just to highlight if there was a transaction on that day. The exact intraday price at whic…
DataError: No numeric types to aggregate pandas pivot
I have a pandas dataframe like this: and I need to convert it to a Matrix like they do here: https://github.com/tr1ten/Anime-Recommender-System/blob/main/HybridRecommenderSystem.ipynb Cell 13. So I did the following: user_training_csr = csr_matrix(user_training_interaction.values) But I get this error: What a…
How to repeat a value in a column based on another
I have the following dataframe: a b 1 None 1 ‘w’ 2 None 2 ‘z’ And I want to repeat the values that are not None in column ‘b’, but based on the value in column ‘a’. At the end I would have this dataframe: a b 1 ‘w’ 1 ‘w’ 2 ‘z’…
Remove string after a predefined string from a nested list of dictionaries with pandas
I have a dataframe with the following structure: How can i Remove string from predefined string with pandas without changing the structure. the predefined string = “from work_text_reviews_count of” the text that i want to remove “from work_text_reviews_count of 450” The expected output…
How to calculate total difference in milliseconds by condition?
I have the following pandas dataframe df: timestamp version actual pred 2022-01-19 11:00:00.600 1 0 0 2022-01-19 11:00:00.800 1 0 1 2022-01-19 11:00:01.200 1 1 0 2022-01-19 11:00:01.800 1 0 0 2022-01-19 11:00:02.200 2 1 1 2022-01-19 11:00:02.600 2 0 0 2022-01-19 11:00:03.200 3 0 1 2022-01-19 11:00:03.600 3 0 …