data-manipulation

Dropping Multiple Columns from a data frame using Python

倾然丶 夕夏残阳落幕 提交于 2019-11-30 20:21:58
I know how to drop columns from a data frame using Python. But for my problem the data set is vast, the columns I want to drop are grouped together or are basically singularly spread out across the column heading axis. Is there a shorter way to slice or drop all the columns with fewer lines of code rather than to write it out like how I have done. The way I have done it here works but I would like a more summarized way. The flight_data_copy_final is the variable in which it should be stored. Here's my code: from IPython.display import display flight_data_copy_version1 = flight_data_copy.drop

Windows command for cutting columns from a text

时光总嘲笑我的痴心妄想 提交于 2019-11-30 19:43:31
The following content is stored in a file: chrome.exe 512 Console 0 73,780 K chrome.exe 800 Console 0 11,052 K chrome.exe 1488 Console 0 92,720 K chrome.exe 1600 Console 0 32,344 K chrome.exe 2240 Console 0 35,132 K chrome.exe 2360 Console 0 21,276 K chrome.exe 3524 Console 0 66,732 K chrome.exe 3924 Console 0 23,524 K Is there a way to extract the 5th column with the Windows command line? Something like the UNIX cut command. for /f "tokens=5 delims= " %i in (file.txt) DO echo %i If you're familiar with the GNU cut utility, you might be better off using the Win32 port: http://gnuwin32

R - Stock market data from csv to xts

懵懂的女人 提交于 2019-11-30 16:14:17
问题 I have this data in a CSV: Date ALICORC1 ALT ATACOBC1 AUSTRAC1 CONTINC1 BVN DNT 40886 5.8 0.1 0.9 0.28 5.45 38.2 1.11 40889 5.8 0.1 0.88 0.28 5.37 37.7 1.04 40890 5.8 0.09 0.87 0.27 5.33 37.4 0.99 40891 5.7 0.1 0.85 0.27 5.3 37.5 0.91 These are stock closing prices from the Peruvian Stock Market, and I want to convert them to xts so I can find the optimal portfolio and other stuff, but I can't find the way to convert this CSV to xts. I've checked out the answer to many of the questions here

Using R to insert a value for missing data with a value from another data frame

无人久伴 提交于 2019-11-30 15:40:29
All, I have a question that I fear might be too pedestrian to ask here, but searching for it elsewhere is leading me astray. I may not be using the right search terms. I have a panel data frame (country-year) in R with some missing values on a given variable. I'm trying to impute them with the value from another vector in another data frame. Here's an illustration of what I am trying to do. Assume Data is the data frame of interest, which has missing values on a given vector that I'm trying to impute from another donor data frame. It looks like this. country year x 70 1920 9.234 70 1921 9.234

How to find differences between two JavaScript arrays of objects?

倖福魔咒の 提交于 2019-11-30 14:42:59
问题 I have two JavaScript arrays orig (the original array of objects) and update (the updated orig array of objects) that have the same length and contain objects, and I want to output the differences between the each pair of objects. Example: var orig = [{enabled:"true", name:"Obj1", id:3},{enabled:"true", name:"Obj2", id:4}]; var update = [{enabled:"true", name:"Obj1", id:3}, {enabled:"true", name:"Obj2-updated", id:4}]; The output should be: name:"Obj2-updated" I implemented something but it

R: create a data frame out of a rolling window

谁说胖子不能爱 提交于 2019-11-30 14:07:20
Lets say I have a data frame with the following structure: DF <- data.frame(x = 0:4, y = 5:9) > DF x y 1 0 5 2 1 6 3 2 7 4 3 8 5 4 9 what is the most efficient way to turn 'DF' into a data frame with the following structure: w x y 1 0 5 1 1 6 2 1 6 2 2 7 3 2 7 3 3 8 4 3 8 4 4 9 Where w is a length 2 window rolling through the dataframe 'DF.' The length of the window should be arbitrary, i.e a length of 3 yields w x y 1 0 5 1 1 6 1 2 7 2 1 6 2 2 7 2 3 8 3 2 7 3 3 8 3 4 9 I am a bit stumped by this problem, because the data frame can also contain an arbitrary number of columns, i.e. w,x,y,z etc.

How to find differences between two JavaScript arrays of objects?

安稳与你 提交于 2019-11-30 11:36:20
I have two JavaScript arrays orig (the original array of objects) and update (the updated orig array of objects) that have the same length and contain objects, and I want to output the differences between the each pair of objects. Example: var orig = [{enabled:"true", name:"Obj1", id:3},{enabled:"true", name:"Obj2", id:4}]; var update = [{enabled:"true", name:"Obj1", id:3}, {enabled:"true", name:"Obj2-updated", id:4}]; The output should be: name:"Obj2-updated" I implemented something but it needs optimization... for(var prop=0; prop<orig.length; prop++) { for(prop=0; prop<update.length; prop++

data.table or dplyr - data manipulation

会有一股神秘感。 提交于 2019-11-30 09:43:50
I have the following data Date Col1 Col2 2014-01-01 123 12 2014-01-01 123 21 2014-01-01 124 32 2014-01-01 125 32 2014-01-02 123 34 2014-01-02 126 24 2014-01-02 127 23 2014-01-03 521 21 2014-01-03 123 13 2014-01-03 126 15 Now, I want to count unique values in Col1 for the each date (that did not repeat in previous date), and add to the previous count. For example, Date Count 2014-01-01 3 i.e. 123,124,125 2014-01-02 5 (2 + above 3) i.e. 126, 127 2014-01-03 6 (1 + above 5) i.e. 521 only lukeA library(dplyr) df %.% arrange(Date) %.% filter(!duplicated(Col1)) %.% group_by(Date) %.% summarise(Count

How to remove groups of observation with dplyr::filter()

别说谁变了你拦得住时间么 提交于 2019-11-30 06:47:39
For the following data ds <- read.table(header = TRUE, text =" id year attend 1 2007 1 1 2008 1 1 2009 1 1 2010 1 1 2011 1 8 2007 3 8 2008 NA 8 2009 3 8 2010 NA 8 2011 3 9 2007 2 9 2008 3 9 2009 3 9 2010 5 9 2011 5 10 2007 4 10 2008 4 10 2009 2 10 2010 NA 10 2011 NA ") ds<- ds %>% dplyr::mutate(time=year-2000) print(ds) How would I write a dplyr::filter() command to keep only the ids that don't have a single NA? So only subjects with ids 1 and 9 should stay after the filter. Robert Krzyzanowski Use filter in conjunction with base::ave ds %>% dplyr::filter(ave(!is.na(attend), id, FUN = all)) To

Windows command for cutting columns from a text

不问归期 提交于 2019-11-30 04:29:09
问题 The following content is stored in a file: chrome.exe 512 Console 0 73,780 K chrome.exe 800 Console 0 11,052 K chrome.exe 1488 Console 0 92,720 K chrome.exe 1600 Console 0 32,344 K chrome.exe 2240 Console 0 35,132 K chrome.exe 2360 Console 0 21,276 K chrome.exe 3524 Console 0 66,732 K chrome.exe 3924 Console 0 23,524 K Is there a way to extract the 5th column with the Windows command line? Something like the UNIX cut command. 回答1: for /f "tokens=5 delims= " %i in (file.txt) DO echo %i 回答2: If