I have the following excel sheet:
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:
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