0

Struggling to get mask to work

Code is below. I'm trying to use a mask array made up of true and false values to filter only rows where the age of the passenger is less than 18. The problem is when I print out my new array it's full of float values and doesnt look like the data at all. The base of this code was taken from the machine learning module in sololearn lesson 7.1. Edit: refactored code for readability and question for clarity import pandas as pd df = pd.read_csv('https://sololearn.com/uploads/files/titanic.csv') df['Row'] = df.index arr = df[['Row','Pclass', 'Fare', 'Age']].values mask = arr[:, 3]<18 print(arr[mask]) print(arr)

26th Nov 2021, 6:07 PM
Alexr1239
4 Antworten
+ 2
It seems that it's just a formatting thing. Add these lines before the print statements to format them in a more readable way: import numpy as np np.set_printoptions(formatter={'float_kind': '{:.2f}'.format})
26th Nov 2021, 11:46 PM
Simon Sauter
Simon Sauter - avatar
+ 1
What are you trying to do?
26th Nov 2021, 6:53 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Thanks that was it!
26th Nov 2021, 11:53 PM
Alexr1239
0
I rewrote the question to be more clear
26th Nov 2021, 7:06 PM
Alexr1239