The below two dataframes df1 and df2 have been manually entered into Python. Then the dataframes were merged into df3. How can I make sure that the final merged dataframe df3 is using the same descending (chronological) order (as for the initial dataframes df1 and df2)(as it is not a case by default)? Thanks …
Tag: dataframe
Merging pandas get_dummies back to categorical values
I have a pandas dataframe which I have one hot encoded with get_dummies, the data previously had a ‘type’ column which contained the values small_airport, large_airport, medium_airport, I split the type column in to each different type of airport with 1s and 0s where the frequencies matched. After…
I cannot change the values of a column with specific condition
The table looks like the following: text dummy1 days op123ac 1 2000-01-01 op123ac 0 2000-01-04 op123ac 0 2000-01-07 op123ac 0 2000-01-10 op1248ab 0 2000-01-17 op1248ab 1 2000-01-20 op1248ab 1 2000-01-23 op1248ab 1 2000-01-26 Each unique “text” have four repeated values correspond to four unique &#…
Add missing rows in pandas DataFrame
I have a DataFrame that looks like this: What I want to get is: In short, for each id, add the time rows missing with value 0. How do I do this? I wrote something with a loop, but it’s going to be prohibitively slow for my use case which has several million rows Answer Here’s one way using groupby…
How to calculate the average R square of the company data [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 10 months ago. Improve this question STOCK RETURN I don’t know how to compute the average r squared with individual stock…
DataFrame has two features how to add a row to split them
I have a DataFrame that contains a column called feature that can have more than one of them as illustrated in the image below row 3 & 4. How do a add a row to the DataFrame that splits the two features: so for row 3 as an example having: and row 4: so the idea is to add a
How do I split a Pandas DataFrame into sub-arrays (specific use case outlined in detail)?
I apologize for the title, but I don’t know enough to properly condense my question into a single line. Here is the use case: I have a pd.DataFrame with arbitrary index values and a column, ‘timestamp’. I have an ordered List of timestamp values. I want to split the DataFrame into chunks wit…
How to run my Python code for every Excel file contained in a folder?
I have a folder named with a certain acronym, and inside this folder you can find a certain number of Excel files. The folder’s name indicates the name of the apartment (for ex. UDC06_45) and, inside this folder, all of the Excel files’ name are composed by: the name of the apartment, followed by …
Trying to get ‘QS’ frequency in pandas for a datetime64[ns] gives attribute error
I am working with an external data source and I am trying to get Quaterstart(QS) frequency for a particular data field. I am providing a dummy data and code below. I am gettinng the following error when I run this Can someone please help me understand what’s happening here? ps: The data given here is du…
Remove rows in a group by until the last row meets some condition
I have the following df We can assume that this data is already sorted. What i need to do is, for every id, I need to remove rows under the following conditions the first entry for every id is type A the last entry for every id is type B the last entry’s B is the last one that appears