[Solved] Writing Specific CSV Rows to a Dataframe

I appreciate being downvoted without given reasons why my question deserves a downvote. I was able to figure it out on my own though. Hopefully, this may answer other people’s questions in the future. import csv import pandas as pd temp = [] #initialize array with open(‘C:/Users/sword/Anaconda3/envs/exceltest/RF_SubjP02_Free_STATIC_TR01.csv’, ‘r’) as csvfile: csvreader = csv.reader(csvfile, delimiter=”,”) for … Read more

[Solved] How to create multiple data frames from a huge data frame using a loop? [closed]

given that your data frame is named veryVeryVERYLargeDF lapply(colnames(veryVeryVERYLargeDF)[2:ncol(veryVeryVERYLargeDF)], function(nameOFColumnInveryVeryVERYLargeDF) cbind(veryVeryVERYLargeDF$ID, veryVeryVERYLargeDF[,nameOFColumnInveryVeryVERYLargeDF])) that will give you a list of somewhatSmallerDFs, where each somewhatSmallerDF is simply the ID column from veryVeryVERYLargeDF and one of the other columns from veryVeryVERYLargeDF 2 solved How to create multiple data frames from a huge data frame using a loop? [closed]

[Solved] Function should clean data to half the size, instead it enlarges it by an order of magnitude

When you merge your dataframes, you are doing a join on values that are not unique. When you are joining all these dataframes together, you are getting many matches. As you add more and more currencies you are getting something similar to a Cartesian product rather than a join. In the snippet below, I added … Read more

[Solved] How to split a list’s value into two lists [closed]

If you have it as datetimeobject: datos[‘day’] = dados[‘time’].dt.date datos[‘time’] = dados[‘time’].dt.time If you have it as string object: datos[‘day’] = dados[‘time’].str[:11] datos[‘time’] = dados[‘time’].str[11:] Or data[[‘day’, ‘time’]] = data[‘time’].str.split(‘ ‘).apply(pd.Series) data[[‘day’, ‘time’]] = data[‘time’].str.split(‘ ‘, expand=True) Or using regex data[[‘day’, ‘time’]] = data[‘time’].str.extract(‘(.*) (.*)’) To convert it to string: datos[‘time’] = dados[‘time’].astype(str) It is … Read more

[Solved] Calculations between two columns in a data frame in R

Here is a solution with base R, where ave() and cumsum() are applied to get the expected: For original data df: dfs <- split(df,df$product) df <- Reduce(rbind,lapply(dfs, function(x) { within(x, expected <- ave(const-value, ave(const-value, cumsum(const>value),FUN = cumsum)>0,FUN = cumsum)) })) such that > df product data value const expected 1 A 2020-01-01 10 100 90 … Read more

[Solved] melting data.frame in R

Here’s a one-liner, base solution: out <- t(apply(mydf, 2, function(x) row.names(mydf)[which(as.logical(x))])) The result is a matrix: > out [,1] [,2] name1 “word1” “word3” name2 “word2” “word3” name3 “word1” “word2” which is easily made into a dataframe: > as.data.frame(out) V1 V2 name1 word1 word3 name2 word2 word3 name3 word1 word2 Here’s your data as I read … Read more

(Solved) Two by two matching between dataframes in r

You want the merge function. Since your column names that you want to match on already have the same name you don’t even need to do anything special. If that wasn’t the case you would want to look into the by.x and by.y parameters that merge takes. df1 = data.frame(Site.1=c(“A”,”A”,”B”),Site.2=c(“B”,”C”,”C”),Score1=c(60,70,80)) df2 = data.frame(Site.1=c(“B”,”A”,”A”),Site.2=c(“C”,”B”,”C”), Score2=c(10,20,30)) df3 … Read more