I have a DataFrame that looks like this: So I have a pair of u and v values (the last two columns). So what I want to ask is, if for example I have a value of u = 279 and a value of v = -108, my output would be Index = 2, is there a way to do
Tag: pandas
how to add new row into each group of groupby in PANDAS , one of the value of that row is sum of values of each groups
let’s say I have a data frame like this I wanted to add a new row into each group of groupby(by=[‘eff_date’,’mdl_cd’,’ast_cd’]) in which column value for eff_date,mdl_cd and ast_cd will remain same but for prop_cd value become Hlds and value value column become sum of…
How to plot a dataframe column of lists as horizontal lines
I have a Dataframe with the column ‘all_maxs’ that could have a list of different values. Current Result I need to plot column ‘c’, and the values of column ‘all_maxs’ that should be horizontal lines. Expected Result Answer Verify the ‘all_maxs’ values are list …
Pandas extract previous row on value change
I have two columns of data ‘Part & Qty’ where some part numbers are repeated across multiple rows. The quantity value I need to retrieve is contained in the final row before the part number changes. My code (below) adds a True/False column to flag when the part number changes. I had thought wh…
How to scrape table data that doesnt have different classes?
Im trying to write some code that will scrape different data from a table on a stock screener website and save the data in excel. The problem I’m having is there isn’t a distinct class code for some of the values I want to pull from the table. so I tried this only for the first header I wanted the
How do you plot two different y-axes using a loop with twinx?
I have a pandas data frame, region, containing the prices of flats (Flat) and detached properties (Detached) in areas of the UK over time (the column Month). I’m trying to obtain plots of the change in price over time of both flats and detached properties, so that the plots have two different y axes …
How to convert dtype from ‘0’ to ‘int64’?
I started working with a dataset, which is a collection of murder reports.There is a column “Perpetrator Age” in which there are simple integers. But when I looked at his type, it turned out that he was dtype(‘O’). In order to work with this column further, I want to change its type to…
how to deal with pandas read_html gracefully when it fails to find a table?
pandas read_html is a great and quick way of parsing tables; however, if it fails to find the table with the attributes specified, it will fail and cause the whole code to fail. I am trying to scrape thousands of web pages, and it is very annoying if it causes an error and termination of the whole program jus…
Splitting a column into 2 in a csv file using python
I have a .csv file with 100 rows of data displayed like this “Jim 1234” “Sam 1235” “Mary 1236” “John 1237” What I’m trying to achieve is splitting the numbers from the names into 2 columns in python edit* Using, I managed to get it to display like this in …
Adding a column to Pandas Dataframe, randomly fill with values with percentage splits
I want to do a test, train, valid on a pandas dataframe, but I do not want to generate new data frames. Rather, I want to add a new column called ‘Split’ where Split = [‘train’,’valid’,’test’]. I want ‘train’, ‘valid’, ‘test’ …