[Solved] Find new and active user each week from user_id and date

so I managed to calculate the count_new by checking the first appearance of a user_id and then merging with initial data adding a column that tell if a user is new by date and id then I counted the new by date: library(dplyr) firstshow<-Orders %>% group_by(user_id) %>% arrange(date) %>% slice(1L) %>% mutate(new = “new”) newdata<-merge.data.frame(Orders,firstshow,by=c(“date”,”user_id”),all … Read more

[Solved] How to sum positive cases by date in python [closed]

you should aggregate by column and then sum the results, try this: Notice that, the patient name should should have a numerical counter for keeping track. import pandas as pd import datetime import numpy as np # this a dummy set, you should have already this in your data frame dict_df = {‘Patient’: [1,2,3,4,5], ‘Positive’: … Read more

[Solved] Deleting specific rows with a pattern[start and end indicators] from a dataframe [closed]

Using a toy example… df <- data.frame(a=LETTERS[1:10],b=LETTERS[3:12],stringsAsFactors = FALSE) limits <- c(“E”,”H”) sapply(df,function(x){ del.min <- grep(limits[1],x) del.max <- grep(limits[2],x) x[del.min:del.max] <- “” return(x)}) a b [1,] “A” “C” [2,] “B” “D” [3,] “C” “” [4,] “D” “” [5,] “” “” [6,] “” “” [7,] “” “I” [8,] “” “J” [9,] “I” “K” [10,] “J” “L” … Read more

[Solved] I want to group Columns in pandas [closed]

Try this: uniq_accounts = differenc[‘AccountID’].unique() grped = differenc.groupby(‘AccountID’) ## You can get the grouped data for a certain AccountId like this and store in a dictionary: d = {} for account in uniq_accounts: d[account] = grped.get_group(account) ##Now, dictionary has all accounts data in separate dataframes. You can access like this: for key in d.keys(): print(d[key]) … Read more

[Solved] How can I create a vector in pandas dataframe from other attributes of the dataframe?

I think you need: df[‘features’] = df.values.tolist() print(df) Atr1 Atr2 features 0 1 A [1, A] 1 2 B [2, B] 2 4 C [4, C] If you have multiple columns and want to select particular columns then: df = pd.DataFrame({“Atr1″:[1,2,4],”Atr2″:[‘A’,’B’,’C’],”Atr3”:[‘x’,’y’,’z’]}) print(df) Atr1 Atr2 Atr3 0 1 A x 1 2 B y 2 4 … Read more

[Solved] Concatenating two string variables in dataframe in R

It would help if you provided more information. Here is an example: df <- data.frame(x=1:26, y=as.factor(LETTERS)) paste(df$x, df$y) [1] “1 A” “2 B” “3 C” “4 D” “5 E”… paste(df$x, df$y, sep=””) [1] “1A” “2B” “3C” “4D” “5E”… It doesn’t matter what class the elements are, the engine will convert them to character class. If … Read more

[Solved] select variable from column in pandas

This will give you filtered dataframe with all the columns where Region is Europe and Purchased Bike is Yes agestock = pd.DataFrame({ ‘Region’: {0: ‘Europe’, 1: ‘Europe’, 2: ‘Europe’, 3: ‘APAC’, 4: ‘US’}, ‘Age’: {0: 36, 1: 43, 2: 48, 3: 33, 4: 43}, ‘Purchased Bike’: {0: ‘Yes’, 1: ‘Yes’, 2: ‘Yes’, 3: ‘No’, 4: … Read more

[Solved] Using python and pandas I need to paginate the results from a sql query in sets of 24 rows into a plotly table . How do I do this?

Using python and pandas I need to paginate the results from a sql query in sets of 24 rows into a plotly table . How do I do this? solved Using python and pandas I need to paginate the results from a sql query in sets of 24 rows into a plotly table . How … Read more

[Solved] splitting url and getting values from that URl in columns

try using a str.split and add another str so you can index each row. data = [{‘ID’ : ‘1’, ‘URL’: ‘https://ckd.pdc.com/pdc/73ba5189-94fd-44aa-88d3-6b36aaa69b02/DDA1610095.zip’}] df = pd.DataFrame(data) print(df) ID URL 0 1 https://ckd.pdc.com/pdc/73ba5189-94fd-44aa-88d… #Get the file name and replace zip (probably a more elegant way to do this) df[‘Zest’] = df.URL.str.split(“https://stackoverflow.com/”).str[-1].str.replace(‘.zip’,”) #assign the type into the next column. … Read more