I have a DataFrame that contains a column with dates which I’d like to use as my DataFrame’s index. The dates in that column are not necessarily unique – sometimes there might be duplicates. I wish to append duplicates as new columns. Dates that are unique can just contain NaN (or whatever) …
Tag: pandas
Pandas – iloc – comparing value to the cell below
For the following table: Using Pandas – I would like achieve the desired_output column, that is TRUE when the value below the current cell i different – otherwise FALSE. I have tried the following code – but error occurs. Answer
Create Dataframe by calling indices of df1 that are listed in df2
I’m new to Python Pandas and struggling with the following problem for a while now. The following dataframe df1 values show the indices that are coupled to the values of df2 that should be called df2 contains the values that belong to the indices that have to be called. For example, df1 shows the value …
Read a TSV file from a remote server
I have this function which returns the path to the file I need to read Later on, I am trying to open the file db_file holds one of the paths above. When I execute the script I get this error: I have checked the files names and the paths they all exist and in the right location. I have tried
Calculate time between two different values in the same pandas column
I have data that look like the following I need to create a new column that will find the time between the first issue and the first resolved. I need a groupby statement that will keep the first issue and the first resolved for all the issues. Then find the time – When I use group by Device and conditio…
How to print MLB data into Pandas DataFrame?
I am still learning how to web scrape and could use some help. I would like to print the MLB data into a Pandas DataFrame. It looks like the program does not run correctly but I did not receive an error. Any suggestions would be greatly appreciated. Thanks in advance for any help that you may offer. Answer Th…
Removing a char from a pandas dataframe column with for loop
I have a DF that has a country column and some of that countries has “(” in it. I tried to remove all of that “(” s with this for loop: But when I print that DF again, I see all parenthesis did not removed. I’d be happy if someone say where I made a mistake. Thanks. Answer You do…
Python how to create a new column that measures proximity to a city?
I have a dataframe with Latitude and Longitude columns, How do I create a column that measures the distance towards a particular location with coordinates (47.631872, -122.217109) In particular I’d like to use the geodesic function from geopy for the distance: from geopy.distance import geodesic. It tak…
Error converting string to date field in Pandas
As you can infer from the above , When I try to convert the string , it gives error. Tried below codes but got same error as,day is not defined, As SO memeber suggested,I edited code but index stills the string, did not convert to day Answer If you don’t want to create another column, then just this wil…
Python: Create lists from diagonal values in a dataframe
I’m trying to create a routine in Python to collect every diagonal group of values in df. Here’s a reproducible example of what I’m trying to achieve: This code returns me one single list: And based on the structure of the given df, what I’m trying to achieve is: From what I’ve s…