Skip to content
Advertisement

Tag: pandas

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 using get_dummies, it looks a bit like this: Basically I need now

Multiply rows in pandas DataFrame depending on values from c

I would like to get from this: nname eemail email2 email3 email4 Stan stan@example.com NO stan1@example.com NO Danny danny@example.com danny1@example.com danny2@example.com danny3@example.com Elle elle@example.com NO NO NO To this: nname eemail Stan stan@example.com Stan stan1@example.com Danny danny@example.com Danny danny1@example.com Danny danny2@example.com Danny danny3@example.com Elle elle@example.com I know I can create 4 separate DFs with name and email column, then merge

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 “days”. “days” are consecutive for each “text”. The problem is that each “text” must have one

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.apply

How to remove brackets from multi-value keys when converting to dataframes or extend values of a key without extraneous characters

The above code handles a nested dictionary to dataframe conversion perfectly fine but if you have a nested dictionary created with the .append() or .extend() method it adds extraneous brackets[] and quotes ” which is making downstream analysis difficult. For example for a nested dictionary like this: created with the setup: And converted to a dataframe with pd.dataframe.from_dict() Creates a

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 return and market return This is what my code looks

Advertisement