From 68f405d91d0efc20ad0b946a58dac29410d52131 Mon Sep 17 00:00:00 2001 From: "Carlos A. Iglesias" Date: Tue, 12 Apr 2016 16:42:51 +0200 Subject: [PATCH] Added substrings_in_string --- ml2/3_5_Exercise_1.ipynb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ml2/3_5_Exercise_1.ipynb b/ml2/3_5_Exercise_1.ipynb index 812c9fd..f6f8484 100644 --- a/ml2/3_5_Exercise_1.ipynb +++ b/ml2/3_5_Exercise_1.ipynb @@ -443,6 +443,12 @@ }, "outputs": [], "source": [ + "def substrings_in_string(big_string, substrings):\n", + "for substring in substrings:\n", + " if big_string.find(substring) != 1:\n", + " return substring\n", + "print(big_string)\n", + "return np.nan\n", "#Turning cabin number into Deck\n", "cabin_list = ['A', 'B', 'C', 'D', 'E', 'F', 'T', 'G', 'Unknown']\n", "df['Deck']=df['Cabin'].map(lambda x: substrings_in_string(x, cabin_list))"