[My excel spreadsheet]

My code:
import pandas as pd
dictionary = pd.read_excel('dictionary.xlsx').to_dict('list')
model_name = input('model name ')
print(dictionary[model_name])
Output when input = model 3:
[11508589.0, 11508572.0, 11508541.0, nan, nan, nan, nan, nan]
Desired output:
[11508589, 11508572, 11508541]
CodePudding user response:
use dropna method in pandas :
print(dictionary[model_name].dropna())
CodePudding user response:
Pandas row has to have values for all columns, NaN marks no value (None).
# ask for column
mn = input('model name ')
# read dataframe, select column, drop NaN
pd.read_excel('dictionary.xlsx')[mn].dropna()
