i have the following Dataframe (df = ) with around 40 mio rows. i try to have the following output: at first i thought to use itertools combinations, it.combinations(Colors[“Colors”],2), but the problem was, that it gives me the combinations of the whole column and don’t correlate to the col…
Tag: pandas
sorting in pandas, while alternating between ascending and descending on the same sorting column
I would like to sort a dataframe by a two columns, but one is always ascending, and the other switches between ascending and descending based on the value of the first column. In other words, when the first column increases, the sorting flips from ascending to descending or vise versa. My motivation for this …
Finding MACD Divergence
I want to create a loop to automate finding MACD divergence with specific scenario/criterion, but I am finding it difficult to execute although its very easy to spot when looking at chart by eyes. Note: you can easily get this as ready available scanner but i want to improve my python knowledge, hope someone …
Change x-axis scale size in a bar graph
For some set of data, here is my code which generates a bar graph like this: The values on the x-axis ranges from 1975 to 2017. And the values on the y-axis are some decimal values. In the x-axis of the plot, the values are overlapping. I want to change the scale as 1975, 1980, 1985 so on to keep
Need help searching a pandas dataframe for a substring from another column
I have a dataframe (called combos) that looks like this (where player_title is an index column, and Team , Opp are regular column headers ) Player_Title Team Opp QB Kirk Cousins MIN @ HOU WR Adam Thielen MIN @ HOU WR Justin Jefferson MIN @ HOU RB Alvin Kamara NO @ DET RB Myles Gaskin MIA vs SEA WR Brandin
how to add a constant column to a dataframe without rows
I am trying to add a column with a constant value to a dataframe that does not have any rows. It appears this isn’t as easy as it would be if the rows were populated. How would one accomplish this? Should yield instead it yields Answer You can use .loc specifying the row index and column label, as follo…
Using a for loop with beautiful soup and if statements to populate a dataframe
Goal: The goal of my project is to use BeautifulSoup aka bs4 to scrape only necessary data from an HTML file and import it into excel. The html file is heavily formatted so unfortunately I haven’t been able to tailor more common solutions to my needs. What I have tried: I have been able to parse the HTM…
How can I perform the following transformation?
I have a dataframe as follows: And I want to convert this dataframe as follows: I tried a few things but nothing worked. Any ideas? Answer Use Series.str.get_dummies with DataFrame.stack: If order is important:
How to compare 2 dictionary values in Python and make pairs with common ones by keys?
I have 2 columns: one is the Pandas DateTime Dataframe (data[“start”]) and the second is the tags, data[“parallels”] for example. So i’m going to create a dictionary, like this: So, the output dictionary is: {3: ‘1.0’, 5: ‘1.0’} How can i check this dictio…
How drop duplicate rows based on a time delta whilst keep the latest occurrence of that record?
I have a table in the form: ID DATE_ENCOUNTER LOAD 151336 2017-08-22 40 151336 2017-08-23 40 151336 2017-08-24 40 151336 2017-08-25 40 151336 2017-09-05 50 151336 2017-09-06 50 151336 2017-10-16 51 151336 2017-10-17 51 151336 2017-10-18 51 151336 2017-10-30 50 151336 2017-10-31 50 151336 2017-11-01 50 151336 …