I have a two columns Pandas data frame containing a list of user_ids and some URLs they have visited. It looks like this: I want to create a vector representation of itself, like this: I’ve tried different things, but keep hitting a wall. Any ideas? Answer What you’re describing is a pivot of the url column This puts the users
Tag: dataframe
Pandas: groupby followed by aggregate – unexpected behaviour when joining strings
Having a pandas data frame containing two columns of type str: which is created as follows: df = pd.DataFrame({“group”:[1,2,2,1],”sc”:[“A”,”B”,”C”,”D”],”wc”:[“word1”, “word2”, “word3″,”word4”]}) When grouping by group and joining the individual columns, I can use: However, when specifying a single column (wc) to perform this operation on: which appears to be a join on the column names. But why is it handled
Combinations of all dataframe columns in python
I have three data frames that have the same index (Countries). I need to find all the combinations of the three data frames, create new columns with the data frames. Under each of those columns I will have the multiplication of the values from those combinations. I tried to use the MultiIndex.from_product but the results is only for the titles:
Handling duplicate values in pandas
I have a dataframe ,that looks like this i don’t want to drop the duplicate items, but i want to change the Active columns value based on Site column,for example Active has to change inactive based on duplicate item in site column,Inactive also have to change based on number of duplicate items present,last duplicate item has to Active, other than
Reshape Pandas DatafRames by binary columns value
Can’t figure out how to reshape my DataFrame into new one by several binary columns value. Input: I want to reshape by binary values, i.e. column a/b/c, if their value == 1, I need every time new column with all data. Expected output: Stucked here from the morning, will appreciate help very much ! Answer Use DataFrame.melt with filtering 1
Is there a way to create columns from a list of phrases?
I have lists of phrases I would like to convert into columns in a dataframe to be used as inputs for a machine learning model. The code should find the unique phrases in all of the rows of data, create columns for the unique rows and indicate if the phrase is present in the row by showing a 1 if
compare unique values of column with corresponding another column values with in a list [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 2 years ago. Improve this question Hi all i have a data frame in unique_id column for all unique unique_id’s i need to check Annotation column for those unique unique_id’s such
pandas group by and fill in the missing time interval sequence
I have a data frame like as shown below What I would like to do is a) FIll in the missing time by generating a sequence number (ex:1,2,3,4) and copy the value (for all other columns) from the previous row I was trying something like below But this doesn’t help me get the expected output I expect my output to
Python : get access to a column of a dataframe with multiindex
Let’s say that I have this dataframe with multi index : How do we get access to the data in the columns “Balance” or “Date”, I do not get why that does not work : or Answer You should use Index.get_level_values: You can pass labels : OR: Pass indices:
How to select specific rows in a dataframe, group them and find the sum using python?
Here is some example data: How can I create a new dataframe which groups the months into seasons and find the total sum of each season frequency, while the output is still a dataframe? I would like something like this: (Winter is where Month = 12, 1, 2)(Spring is where Month = 3, 4, 5)(etc….) I have tried to select