Assuming I have a toy model df which lists the model of the car and customer rating of one car showroom. Using plotly express, I created pie charts of percentage of cars by model and by Cust_rating, respectively as two separate graphs: Now, I want to create subplots, and all the ways of doing it using the doc…
Tag: pandas
Updating columns of list based on match
Purpose The main purpose is to be able to compute the share of resources used by node i in relation to its neighbors: r_i / sum_j^i{r_j} where r_i are node i resources and sum_j^i{r_j} is the sum of i’s neighbors’ resources. I am open to any R, python or eventually stata solutions, that are able t…
How to merge multiple columns of a dataframe using regex?
I have a df which as following Here what I want to do is combine those columns and we have two rules: If a column removes _C{0~9} or _C{0~9}{0~9} or _C{0~9}{0~9}{0~9} is equal to another column, these two columns can be combined. Let’s take number_C1_E1 number_C2_E2 number_C3_E1 as an example, here numb…
Combine rows and average column if another column is minimum
I have a pandas dataframe: Basically, I would like to average the Power for each server but only if the difference is minimum. For example, if you look at the ‘PhysicalWindows1’ server, I have 3 rows, two have a diff of 100, and one has a diff of 500. Since I have two rows with a diff of 100, I
How do I separate measurement value and unit into their respective columns if they appear together in DataFrame?
I have a DataFrame which contains measurements; e.g., weight, height, etc. However, sometimes the measurement column contains units together with values. Therefore, I would like to separate measurement values and units if they are together in DataFrame. Eg., In the below DataFrame, df, the height value and un…
Substitute column values of a dataframe with the corresponding items in an array
I have a column in a dataframe which contains an array of numbers from 1 to 5 and I have an array containing five words. I would like to find the simplest, most compact and most elegant way in Python to “in place” replace the numbers in the column with the corresponding words. For example: I am ce…
Sort the products based on the frequency of changes in customer demand
Imagine following dataframe is given. I have columns products, custome_demand_date (every week there is new customer demand for products per upcoming months) and months with quantity demand. How can I determine which product has experienced the most frequent changes in customer demand over the months, and sor…
Loop through a dataframe, using specific values for individual dates
I have a dataframe that looks like the below. I want to create a new column titled ‘Daily Change’ which will be the result of the first ‘Open’ price of each day divided by the ‘Open’ price for each 5 minute interval. Once the dates changes I need to the first open price of …
Python panda’s dataframe boolean Series/Column based on conditional next columns
I’m having trouble describing exactly what I want to achieve. I’ve tried looking here on stack to find others with the same problem, but are unable to find any. So I will try to describe exactly what I want and give you a sample setup code. I would like to have a function that gives me a new colum…
Why can’t I save my scraped html table to pandas dataframe?
I have a python script that scrapes a html table. When I try to save my scraped data to pandas dataframe, I get an error. Please help me check what am doing wrong? Here is my codeblock Here is the error i get I want to save the above scraped values into pandas dataframe. That’s my aim. Please help if