I have a Pandas DataFrame with the coordinates of different cell towers where one column is the Latitude and another column is the Longitude like this: and so on I need to get the distances between each cell tower and all the others, and subsequently between each cell tower and its closest neighbouring tower.…
Tag: pandas
Color formatting excel file row in python
I have dataframe where I have 2 Date columns. I have to compare them and if they are different then whole row should be colored. Please check the picture. Please guide me how can I do that in python. Thanks in advance. Answer Create styles in helper DataFrame and export to excel:
Pandas rolling apply function to entire window dataframe
I want to apply a function to a rolling window. All the answers I saw here are focused on applying to a single row / column, but I would like to apply my function to the entire window. Here is a simplified example: This is df: Take some function to apply to the entire window: In this example, I would
Split data frame into multiple data frames based on a group of parameters in a column
I’ve got a data frame like this: DF And I need to split it in multiple data frames by PARAMETER_4 in C column, to get: DF_1 DF_2 DF_3 I cannot find any easy-way function like df.split(axis=0, value=’PARAMETER_4′) Any idea about an approach? Thank you in advance! Answer We can use groupby twi…
Cleaning up data frame and date time
I am working with data frame. One of the columns contains date where the format of cell are mixed between date, time and string. The sample date frame is as follow: I want to create a new column that contains the text of date column. The expected output is as follows: How can I do that? Answer IIUC using to_d…
How to combine 2 dataframe histograms in 1 plot?
I would like to use a code that shows all histograms in a dataframe. That will be df.hist(bins=10). However, I would like to add another histograms which shows CDF df_hist=df.hist(cumulative=True,bins=100,density=1,histtype=”step”) I tried separating their matplotlib axes by using fig=plt.figure()…
Does loc/iloc return a reference or a copy?
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…
Why does Excel styling not work in Pandas?
I tried to apply highlight_max to columns Answer So I’m going to assume you want to apply your style change to your dataframe in python the way it is designed to be implemented and display the color modifications when you print your dataframe in console. The issue is (I’m assuming) that you are no…
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 data…
Pandas ‘partial melt’ or ‘group melt’
I have a DataFrame like this and I want to transform it into something like this This is an unpivot / melt problem, but I don’t know of any way to melt by keeping these groups intact. I know I can create projections across the original dataframe and then concat those but I’m wondering if I’m…