after pre processing the data i keep getting Nan values in the test set code example
Example: whow i fill the data if most values are nan in jupyter notebook
import pandas as pd
list_of_rows = [
{'start_station': 1, 'end_station': 1},
{'start_station': None, 'end_station': 1},
{'start_station': 1, 'end_station': 2},
{'start_station': 1, 'end_station': 3},
{'start_station': 2, 'end_station': None},
{'start_station': 2, 'end_station': 3},
{'start_station': 2, 'end_station': 3},
]
df = pd.DataFrame(list_of_rows)
def fill_NaNs_in_end_station(row):
if pd.isnull(row['end_station']):
start_station = row['start_station']
return df[df['start_station']==start_station].end_station.value_counts().first_valid_index()
return row['end_station']
df['end_station'] = df.apply(lambda row: fill_NaNs_in_end_station(row), axis=1)