I am experiencing some problems while using .loc / .iloc as part of a loop. This is a simplified version of my code: basically: I initialize a dataframe with index and columns I populate each row of the dataframe with a for loop I find the index “i_max” finding the maximum value in column ‘A’ I save the row of
Tag: pandas
Append only matching columns to dataframe
I have a sort of ‘master’ dataframe that I’d like to append only matching columns from another dataframe to The problem is that when I use df.append(), It also appends the unmatched columns to df. But my desired output is to drop columns D and E since they are not a part of the original […]
pandas read_html – no tables found
I am attempting to see if I can read a table of data from WU.com, but I am getting a type error for no tables found. (first timer on web scraping too here) There is also another person with a very …
How to zip together lists of unequal length into a dictionary?
I have three lists. I’d like to make these lists into a dataframe in which each row is the author paired with each coauthor and the frequency of collaborations. Basically if I could zip these three lists together, with the list ‘author’ replicated over and over in each row, this would be great. This seems […]
matplotlib: draw a box on axes
I want to draw the box between y=75 and 90 (green and red lines on the chart), but nothing is shown up when I do ax.add_patch this is the image I get: So How do I fill out the area between red and green horizontal lines? AdvertisementAnswer If you have a fixed area you want […]
Extracting 2gram strings from a column present in a list
I have a dataframe called df and a list called algorithms So technically, for each row of the Comments column, I’m trying to extract words that appear in the algorithms list. This is what I’m trying to achieve However, this is what I’m getting words like machine learning and fraud detection don’t appear. basically, all […]
A few operations with df.groupby()
I working with a forex dataset, trying to fill in my dataframe with open, high, low, close updated every tick. Here is my code: So as you can see, with for loop I’m getting groups. Now I want to fill the following columns in my dataframe: idx be my df[‘candle_number’] df[‘1h_open’] must be equal to […]
Remove default formatting in header when converting pandas DataFrame to excel sheet
This is something that has been answered and re-answered time and time again because the answer keeps changing with updates to pandas. I tried some of the solutions I found here and elsewhere online and none of them have worked for me on the current version of pandas. Does anyone know the current, March 2019, pandas 0.24.2, fix for removing
Rename dataframe columns with a mapper function that takes parameters
How can I pass along parameters to a mapper function in pandas.DataFrame.rename? The example below uses a mapper function test. I want to change it’s behavior based on an additional parameter that I pass along. In this example, the mapper function appends an “A” to each column name. I want the mapper not always to append an “A” but a
Pandas: splitting data frame based on the slope of data
I have this data frame x = pd.DataFrame({‘entity’:[5,7,5,5,5,6,3,2,0,5]}) Update: I want a function If the slope is negetive and the length of the group is more than 2 then it should return True, …