dataframe

How can I resample (upsample) my Pandas Dataframe?

回眸只為那壹抹淺笑 提交于 2021-01-28 14:49:34
问题 I have a small Pandas DataFrame I'd like to resample, and I hoped you could help me :) I cannot show it to you as it is confidential but I can describe to you a simpler version of it. It has 4 columns: -Date (YYYY-MM-DD format) -Country -Amount -Frequency So here is what I'd like to do: Depending on the rows, the Frequency is either YEARLY or MONTHLY If it happens to be monthly, then nothing needs to be done. But if it's YEARLY, I would like to change it to MONTHLY and insert 11 new rows so

How can I resample (upsample) my Pandas Dataframe?

扶醉桌前 提交于 2021-01-28 14:32:27
问题 I have a small Pandas DataFrame I'd like to resample, and I hoped you could help me :) I cannot show it to you as it is confidential but I can describe to you a simpler version of it. It has 4 columns: -Date (YYYY-MM-DD format) -Country -Amount -Frequency So here is what I'd like to do: Depending on the rows, the Frequency is either YEARLY or MONTHLY If it happens to be monthly, then nothing needs to be done. But if it's YEARLY, I would like to change it to MONTHLY and insert 11 new rows so

Join big dataframe in r and filter in the same time

笑着哭i 提交于 2021-01-28 14:30:35
问题 df1 = data.frame(id=1,start=as.Date("2012-07-05"),end=as.Date("2012-07-15")) df2 = data.frame(id=rep(1,1371),date = as.Date(as.Date("2012-05-06"):as.Date("2016-02-05"))) output = dplyr::inner_join(x=df1,y=df2,by="id") %>% filter(date>=start & date<= end) I have two dataframes which have each one about one millions rows and I want to join them by id and then filter so that for each row, value of column date is comprised between value of startdate and enddate. An dplyr::inner_join is not

Select Pandas dataframe rows between two dates

有些话、适合烂在心里 提交于 2021-01-28 14:25:31
问题 I am working on two tables as follows: A first table df1 giving a rate and a validity period: rates = {'rate': [ 0.974, 0.966, 0.996, 0.998, 0.994, 1.006, 1.042, 1.072, 0.954], 'Valid from': ['31/12/2018','15/01/2019','01/02/2019','01/03/2019','01/04/2019','15/04/2019','01/05/2019','01/06/2019','30/06/2019'], 'Valid to': ['14/01/2019','31/01/2019','28/02/2019','31/03/2019','14/04/2019','30/04/2019','31/05/2019','29/06/2019','31/07/2019']} df1 = pd.DataFrame(rates) df['Valid to'] = pd.to

how combine two list of dataframes by names

坚强是说给别人听的谎言 提交于 2021-01-28 14:01:54
问题 I have two list of dataframes, like: names1 <- c("1", "2") mydf1 <- data.frame(V1=c(1:2), V2=rep("A",2)) mydf2 <- data.frame(V1=c(1:3), V2=rep("B",3)) list1 <- list(mydf1,mydf2) names2 <- c("1","1","2") mydf4 <- data.frame(V1=c(1:3), V2=rep("BB",3)) mydf5 <- data.frame(V1=c(1:3), V2=rep("CC",3)) mydf6 <- data.frame(V1=c(1:3), V2=rep("DD",3)) list2 <- list(mydf4,mydf5,mydf6) names(list1) <- names1 names(list2) <- names2 and I want combine into lists by equal names. I want something like that:

How to combine multiple columns of an r data frame into a single column that is a list

為{幸葍}努か 提交于 2021-01-28 13:32:28
问题 I would like to combine multiple columns that I have in a data frame into one column in that data frame that is a list. For example, I have the following data frame ingredients: name1 name2 imgID attr1 attr2 attr3... Item1 ItemID1 Img1 water chocolate soy... Item2 ItemID2 Img2 cocoa spice milk... I would like to combine the attr columns into one column that is a comma-separated list of those items and if possible have them appear in the following format: name1 name2 imgID attrs Item1 ItemID1

Unlist column in data frame with listed

霸气de小男生 提交于 2021-01-28 12:53:26
问题 I have a list with multiple levels that I would like to the data level into a data frame, where the variable chr is collapsed into single strings. myList <- list(total_reach = list(4), data = list(list(reach = 2, chr = list("A", "B", "C"), nr = 3, company = "Company A"), list(reach = 2, chr = list("A", "B", "C"), nr = 3, company = "Company B"))) I would like to transform this into a data frame that looks like this: reach chr nr company 1 2 A, B, C 3 Company A 2 2 A, B, C 3 Company B Using

Unlist column in data frame with listed

為{幸葍}努か 提交于 2021-01-28 12:52:11
问题 I have a list with multiple levels that I would like to the data level into a data frame, where the variable chr is collapsed into single strings. myList <- list(total_reach = list(4), data = list(list(reach = 2, chr = list("A", "B", "C"), nr = 3, company = "Company A"), list(reach = 2, chr = list("A", "B", "C"), nr = 3, company = "Company B"))) I would like to transform this into a data frame that looks like this: reach chr nr company 1 2 A, B, C 3 Company A 2 2 A, B, C 3 Company B Using

Unlist column in data frame with listed

怎甘沉沦 提交于 2021-01-28 12:50:33
问题 I have a list with multiple levels that I would like to the data level into a data frame, where the variable chr is collapsed into single strings. myList <- list(total_reach = list(4), data = list(list(reach = 2, chr = list("A", "B", "C"), nr = 3, company = "Company A"), list(reach = 2, chr = list("A", "B", "C"), nr = 3, company = "Company B"))) I would like to transform this into a data frame that looks like this: reach chr nr company 1 2 A, B, C 3 Company A 2 2 A, B, C 3 Company B Using

Saving multiple dataframes to multiple excel sheets multiple times?

好久不见. 提交于 2021-01-28 12:40:07
问题 I have a function to save multiple dataframes as multiple tables to single excel workbook sheet: def multiple_dfs(df_list, sheets, file_name, spaces): writer = pd.ExcelWriter(file_name,engine='xlsxwriter') row = 0 for dataframe in df_list: dataframe.to_excel(writer,sheet_name=sheets,startrow=row , startcol=0) row = row + len(dataframe.index) + spaces + 1 writer.save() If I call this function multiple times to write multiple tables to multiple sheets, I end up with just one workbook and one