Skip to content

Commit ebfa126

Browse files
committed
segments py3
1 parent 9fb4eee commit ebfa126

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

projects/customer_segments/customer_segments.ipynb

100755100644
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
{
3737
"cell_type": "code",
3838
"execution_count": null,
39-
"metadata": {
40-
"collapsed": true
41-
},
39+
"metadata": {},
4240
"outputs": [],
4341
"source": [
4442
"# Import libraries necessary for this project\n",
@@ -56,9 +54,9 @@
5654
"try:\n",
5755
" data = pd.read_csv(\"customers.csv\")\n",
5856
" data.drop(['Region', 'Channel'], axis = 1, inplace = True)\n",
59-
" print \"Wholesale customers dataset has {} samples with {} features each.\".format(*data.shape)\n",
57+
" print(\"Wholesale customers dataset has {} samples with {} features each.\".format(*data.shape))\n",
6058
"except:\n",
61-
" print \"Dataset could not be loaded. Is the dataset missing?\""
59+
" print(\"Dataset could not be loaded. Is the dataset missing?\")"
6260
]
6361
},
6462
{
@@ -104,7 +102,7 @@
104102
"\n",
105103
"# Create a DataFrame of the chosen samples\n",
106104
"samples = pd.DataFrame(data.loc[indices], columns = data.keys()).reset_index(drop = True)\n",
107-
"print \"Chosen samples of wholesale customers dataset:\"\n",
105+
"print(\"Chosen samples of wholesale customers dataset:\")\n",
108106
"display(samples)"
109107
]
110108
},
@@ -330,7 +328,7 @@
330328
" step = None\n",
331329
" \n",
332330
" # Display the outliers\n",
333-
" print \"Data points considered outliers for the feature '{}':\".format(feature)\n",
331+
" print(\"Data points considered outliers for the feature '{}':\".format(feature))\n",
334332
" display(log_data[~((log_data[feature] >= Q1 - step) & (log_data[feature] <= Q3 + step))])\n",
335333
" \n",
336334
"# OPTIONAL: Select the indices for data points you wish to remove\n",
@@ -704,7 +702,7 @@
704702
"source": [
705703
"# Display the predictions\n",
706704
"for i, pred in enumerate(sample_preds):\n",
707-
" print \"Sample point\", i, \"predicted to be in Cluster\", pred"
705+
" print(\"Sample point\", i, \"predicted to be in Cluster\", pred)"
708706
]
709707
},
710708
{
@@ -820,21 +818,21 @@
820818
],
821819
"metadata": {
822820
"kernelspec": {
823-
"display_name": "Python 2",
821+
"display_name": "Python 3",
824822
"language": "python",
825-
"name": "python2"
823+
"name": "python3"
826824
},
827825
"language_info": {
828826
"codemirror_mode": {
829827
"name": "ipython",
830-
"version": 2
828+
"version": 3
831829
},
832830
"file_extension": ".py",
833831
"mimetype": "text/x-python",
834832
"name": "python",
835833
"nbconvert_exporter": "python",
836-
"pygments_lexer": "ipython2",
837-
"version": "2.7.12"
834+
"pygments_lexer": "ipython3",
835+
"version": "3.6.2"
838836
}
839837
},
840838
"nbformat": 4,

projects/customer_segments/visuals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def pca_results(good_data, pca):
2525
dimensions = dimensions = ['Dimension {}'.format(i) for i in range(1,len(pca.components_)+1)]
2626

2727
# PCA components
28-
components = pd.DataFrame(np.round(pca.components_, 4), columns = good_data.keys())
28+
components = pd.DataFrame(np.round(pca.components_, 4), columns = list(good_data.keys()))
2929
components.index = dimensions
3030

3131
# PCA explained variance
@@ -132,7 +132,7 @@ def channel_results(reduced_data, outliers, pca_samples):
132132
try:
133133
full_data = pd.read_csv("customers.csv")
134134
except:
135-
print "Dataset could not be loaded. Is the file missing?"
135+
print("Dataset could not be loaded. Is the file missing?")
136136
return False
137137

138138
# Create the Channel DataFrame

0 commit comments

Comments
 (0)