Entering edit mode
3.7 years ago
elhamidihay
▴
30
I have a fairly large dataset, I would like to read data from a file and sum values equal to 1 for every row and write it to a file. My code just prints data back to me
Example input file:
1526 0 1 2 1 0
782 0 1 1 1 2
7653 1 1 1 0 0
87bt 1 0 1 2 2
Example desired output file:
1526 2
782 3
7653 3
87bt 2
my code:
df = pd.read_csv("data1", header=None, index_col=0)
df.eq(1).sum(axis=1)