Off topic:Looping over a section of data and suming in python
0
0
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)
python pandas numpy • 262 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1949 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6