All Questions

53
votes
10answers
165509 views

Convert multiple rows into one with comma as separator

If I issue SELECT username FROM Users I get this result: username -------- Paul John Mary but what I really need is one row with all the values separated by comma, like this: Paul, John, Mary ...
421
votes
7answers
443079 views

How to iterate over rows in a DataFrame in Pandas?

I have a DataFrames from pandas: import pandas as pd inp = [{'c1':10, 'c2':100}, {'c1':11,'c2':110}, {'c1':12,'c2':120}] df = pd.DataFrame(inp) print df Output: c1 c2 0 10 100 1 11 110 2 ...
94
votes
11answers
141455 views

Compare two data.frames to find the rows in data.frame 1 that are not present in data.frame 2

I have the following 2 data.frames: a1 <- data.frame(a = 1:5, b=letters[1:5]) a2 <- data.frame(a = 1:3, b=letters[1:3]) I want to find the row a1 has that a2 doesn't. Is there a built in fun...
6
votes
4answers
6837 views

How to delete rows from a dataframe that contain n*NA

I have a number of large datasets with ~10 columns, and ~200000 rows. Not all columns contain values for each row, although at least one column must contain a value for the row to be present, I would ...
3
votes
2answers
1052 views

remove IDs that occur x times R

I have a df and I would like to remove people who have less than X amount of rows in df. E.g., in this toy example, I would like to retain people who have >= 5 rows. df names fruit 4 john ki...
81
votes
5answers
221218 views

How to append rows to an R data frame

I have looked around StackOverflow, but I cannot find a solution specific to my problem, which involves appending rows to an R data frame. I am initializing an empty 2-column data frame, as follows. ...
44
votes
8answers
47715 views

Repeat rows of a data.frame

I want to repeat the rows of a data.frame, each N times. The result should be a new data.frame (with nrow(new.df) == nrow(old.df) * N) keeping the data types of the columns. Example for N = 2: ...
3
votes
4answers
42516 views

Create text Files from every row in an Excel spreadsheet

I need help creating separate text files from each row in an excel spread sheet called "worksheet". I want the text files to be named with content of Column A, with columns B-G being the content, pre...
78
votes
5answers
173141 views

Numpy - add row to array

How does one add rows to a numpy array? I have an array A: A = array([[0, 1, 2], [0, 2, 0]]) I wish to add rows to this array from another array X if the first element of each row in X meets a spe...
15
votes
4answers
70294 views

Removing specific rows from a dataframe

I have a data frame e.g.: sub day 1 1 1 2 1 3 1 4 2 1 2 2 2 3 2 4 3 1 3 2 3 3 3 4 and I would like to remove specific rows that can be ...

Previous Next