title: Remove NaNs from a data set and set casting type
body: <p>My problem is following: I want to prepare a data set for Tensorflow and need to get rid of Nans.
  But when I turn it into an array the Nans are still there even after running .dropna() or .fillna().</p>
  
  <p>The error it throws it that it cannot remove the errors because of the casting type and as a result I cannot use the split function.
  Can anybody explain to me why this casting type is preventing me from deleting the Nans?
  <strong>Python version: 3.7</strong></p>
  
  <pre><code># -*- coding: utf-8 -*-
  """
  Created on Thu Oct 24 12:01:09 2019
  
  @author: bill-
  """
  
  #load the transaction data and all packages
  import pandas as pd
  import numpy as np
  import os
  from sklearn.preprocessing import LabelEncoder
  from sklearn.model_selection import train_test_split
  #%%
  #switching the backslashes to slashes
  link = r"C:\Users\bill-\Desktop\TransactionsD.csv"
  new_link = link.replace(os.sep, '/')
  file = ''.join(('', new_link,''))
  
  #load the data and skip the first row, then rename the columns to something informative
  #columns
  #date = date of transaction
  #trans_cat = category of transaction
  #subcat = subcategory
  #shopname = shop name
  #amount = amount in USD
  #####
  #index_col = None uses first column automatically
  #index_col = False uses no index at all
  data = pd.read_csv(file, skiprows = 1, index_col = False, na_values = 0,  names = ['date',
                                                                     'category',
                                                                     'trans_cat',
                                                                     'subcat',
                                                                     'shopname',
                                                                     'amount'])
  
  #%%
  #LabelEncoder for category, trans_cat, shopname
  #use the LabelEncoder to make shopname numerical
  LE = LabelEncoder()
  data['LE_shopname'] = LE.fit_transform(data['shopname'])
  #this one doesnt work
  data['LE_category'] = LE.fit_transform(data['category'])
  
  #category does not support conversion of strings; is being converted to numbers and then to integers values
  #change to categorical data which also does not allow me to remove NaNs
  #data['category'] = pd.Categorical(data['category'])
  #change to float number AND drop all kinds of NaNs for potential preprocessing
  #KEEP COPY TRUE TO AVOID BREAKING INHERITED FEATURES!
  data['category'].fillna(value = 0)
  data['category'] = data['category'].astype('float32', copy = True, errors = 'raise')
  
  #do not create a new column but change the old one
  data['LE_category'] = data.replace(to_replace={'category': {'nan': 0},
                                                  'category': {'Shops': 1},
                                                  'category': {'Food and Drink': 2},
                                                  'category': {'Travel': 3},
                                                  'category': {'Service': 4},
                                                  'category': {'Transfer': 5},
                                                  'category': {'Community': 6},
                                                  'category': {'Bank Fees': 7},
                                                  'category': {'Recreation': 8}},
                                                  value = None)
  
  #READY UP DATA TO BE READY FOR FEATURES AND PASS IT TO TENSOR FLOW
  data_features = data.drop(['date', 'trans_cat','subcat', 'shopname', 'LE_shopname'], axis = 1)
  #convert it to an array to make it a feature
  model_features = data_features.to_numpy(dtype = 'float32', copy = True)
  #no labels to see if tensor can handle the input
  model_label = data['LE_shopname'].to_numpy(dtype = 'float32', copy = True)
  #%%
  #INPUT: PANDAS DATA FRAMER
  #OUTPUT: OBJECT TYPE THAT CANT BE USED FOR FURTHER OPERATIONS IF IT IS NOT CONVERTED TO A DATA FRAME AGAIN
  
  
  #%%
  #train_test_split seems to take 2 times the identical data frame
  #DATA_FEATURES=LOADED TRANSACTION DATA
  #category       category
  #subcat          float64
  #amount          float64
  #LE_shopname       int32
  
  #Equation: category + subcategory + amount ~ LE_shopname
  
  #splitting of the data
  #look up structure of train test split; since x= and y=  doesnt work sometimes
  X_train, X_test, y_train, y_test = train_test_split(model_features, model_label, test_size = 0.3)```
  
  </code></pre>