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)
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})
+ 1
What are you trying to do?
+ 1
Thanks that was it!
0
I rewrote the question to be more clear