Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print excel column non null value with python?

I have the following excel sheet:enter image description here

and want to print column 1 value if the column 2 value is not null. The output should be [1,3].

This the script created by me, but it doesn’t work:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import xlrd
import pandas as pd

filename='test.xlsx'
dataframe = pd.read_excel(filename)
frame = dataframe.loc[dataframe["col2"] !=" "]
df =  frame.iloc[:, 0]

ndarray = df.to_numpy()
print(ndarray)

>Solution :

You can first filter down to nona rows and then show the values of the column you want to show:

dataframe[df['col2'].notna()]['col1'].values
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading