Skip to content

Instantly share code, notes, and snippets.

@Lawrence-Krukrubo
Last active May 30, 2020 23:45
Show Gist options
  • Save Lawrence-Krukrubo/a02740111d89297bb3b60cbadc521e7b to your computer and use it in GitHub Desktop.
Save Lawrence-Krukrubo/a02740111d89297bb3b60cbadc521e7b to your computer and use it in GitHub Desktop.
Adding code snippets to my article (Loading Different Data Sets) on Medium
# First, let's import numpy.
import numpy as np
# Next, let's save the titanic_df we loaded before, as titanic.csv file.
titanic_df.to_csv('titanic.csv', index=False)
# Next, let's load titanic.csv as a numpy array,
titanic_arr = np.loadtxt('titanic.csv', delimiter = ',', skiprows=1, usecols=[0,1,4])
# I passed the following parameters:-
# 1. delimiter = ',' (which is an optional param)
# 2. skiprows=1, to skip the first row with the col headers
# 3. I pass usecols=[0,1,4], to only select 3 numerical cols.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment