Data frames that look like this
0 1 2 4
1 0 2 5
3 4 0 0
From
I want to print out the number of columns with zero in the last row with two zeros
Coding to be done
It's complicated.So the final result is to print out the numbers in columns 3 and 4.
It's not easy to get the results you want. It's hard to count the number of zeros in a data frame, so I'm asking you this question.
python dataframe
I can do it like this.
import pandas as pd
df = pd.DataFrame([[0,1,2,4], [1,0,2,5],[3,4,0,0]])
# # print(df)
for row_idx, row in enumerate(df.itertuples(index=False)):
if row.count(0) >= 2:
# # print(row)
print(row_idx+1)
print(" ".join([ str(i+1) for i, d in enumerate(row) if d == 0 ]))
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
619 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.