'int' object is not callable when calculating min - python

I am having a very weird and frustrating error.
The problem is very simple:
>>> mylist
[70.71, 67.23, 60.1, 62.52, 64.14, 65.4, 68.84, 61.04, 66.95, 62.22, 63.73, 62.04, 57.12, 61.3, 65.48, 61.49, 66.94, 62.68, 60.31, 64.38, 62.84, 63.03, 67.12, 60.65, 61.68, 64.0, 62.91, 61.36, 60.65, 62.45, 64.22, 66.4, 59.96, 57.03, 66.4, 60.43, 64.05, 64.09, 50.94, 39.84, 45.12, 63.39, 55.62, 55.58, 58.04, 59.91, 60.05, 57.3, 61.83, 63.87, 50.58, 62.56, 60.75, 58.9, 62.99, 61.65, 59.09, 59.91, 64.66, 61.1, 61.31, 59.62, 56.65, 60.1, 66.04, 60.57, 59.77, 53.0, 60.84, 61.75, 64.53, 52.0, 62.08, 67.69, 60.62, 55.04, 54.49, 30.82, 48.32, 59.66, 62.56, 66.71, 70.4, 55.13, 59.32, 63.06, 56.0, 56.19, 65.9, 61.01, 62.03, 59.43, 62.82, 56.83, 62.91, 76.44, 68.01, 61.0, 63.51, 58.12, 65.77, 56.88, 63.18, 69.03, 63.34, 54.91, 60.25, 64.79, 64.17, 61.86, 53.05, 63.42, 57.08, 60.36, 59.62, 64.69, 59.78, 58.34, 65.19, 55.49, 73.53, 56.25, 61.09, 53.35, 63.45, 64.34, 29.79, 59.75, 67.7, 59.74, 52.17, 61.29, 58.88, 55.68, 55.81, 57.52, 62.0, 62.49, 60.47, 61.86, 56.94, 56.31, 61.82, 62.01, 59.99, 59.4, 57.9, 63.08, 64.56, 60.77, 63.95, 60.1, 66.22, 58.05, 66.25, 62.34, 61.17, 64.04, 64.08, 61.1, 56.19, 61.04, 53.13, 64.58, 60.96, 58.97, 59.43, 66.22, 58.4, 55.68, 35.47, 42.6, 57.57, 58.3, 60.84, 62.52, 54.86, 60.9, 60.99, 60.47, 61.45, 58.34, 62.17, 63.68, 62.4, 64.62, 56.78, 59.14, 61.47, 54.7, 55.3, 58.09, 62.95, 61.47, 57.69, 62.45, 54.86, 58.51, 60.52, 54.56]
An now I try to get the min value:
>>> min(mylist)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
Why?

Most probably you have a variable named min that shadowed the built in min function. If you are using the interactive console just do:
del min
Also consider using numpy, as it can be faster on bigger lists:
>>> import numpy
>>> numpy.min(mylist)

I can not reproduce this. min(mylist) returns 29.79.
You are probably using a variable called min in your code. Don't do this.

Related

Max of values from 3 columns in a dataframe?

I would like to calculate the maximum of 3 columns value.
import pandas as pd
import pandas_datareader.data as web
data = web.DataReader("^NSEI" , data_source="yahoo",start = "1/4/2016",end ="6/4/2018")
data=pd.DataFrame(data)
data["High-Low"] = data["High"] - data["Low"]
data["Close-low"] = abs(data["Close"].shift(1) - data["Low"])
data["Close-High"] = abs(data["Close"].shift(1) - data["High"])
data["True_Range"] = data[[data["High-Low"], data["Close-low"],data["Close-High"]]].max(axis=1)
In data["True _Range"] column, I want to take the maximum of value in data["High-low"],data["Close-low"] and data["Close-high"] columns. On this, it is giving a name error.
KeyError: "None of [Index([(156.44970703125, 67.9501953125, 79.75, 118.35009765625, 53.05029296875, 110.75, 100.5, 165.150390625, 161.0, 139.2001953125, 127.25, 98.60009765625, 229.39990234375, 148.7001953125, 105.7998046875, 65.94970703125, 58.19970703125, 59.25, 172.85009765625, 59.2001953125, 148.25, 69.10009765625, 91.099609375, 96.5, 149.349609375, 48.30029296875, 94.10009765625, 248.69970703125, 165.7998046875, 126.0, 166.94970703125, 163.05029296875, 87.25, 80.89990234375, 51.69970703125, 151.0, 81.0498046875, 72.80029296875, 67.7998046875, 268.80029296875, 200.39990234375, 72.2001953125, 77.900390625, 61.7998046875, 85.0, 114.7001953125, 99.7001953125, 83.35009765625, 68.650390625, 92.400390625, 102.85009765625, 105.89990234375, 95.7001953125, 95.849609375, 84.400390625, 56.25, 161.69970703125, 70.64990234375, 98.5, 75.60009765625, 74.0498046875, 60.05029296875, 147.64990234375, 46.89990234375, 94.89990234375, 42.64990234375, 161.94970703125, 54.0498046875, 92.599609375, 77.85009765625, 72.85009765625, 94.35009765625, 50.0, 84.0, 151.9501953125, 50.4501953125, 157.5498046875, 100.349609375, 52.5, 155.10009765625, 51.75, 70.69970703125, 60.5498046875, 120.10009765625, 59.19970703125, 112.2001953125, 66.39990234375, 96.7998046875, 101.75, 60.39990234375, 71.2998046875, 109.400390625, 76.64990234375, 98.39990234375, 45.75, 131.900390625, 134.5, 87.150390625, 49.2001953125, 79.2998046875, ...), (nan, 28.0498046875, 63.44970703125, 184.39990234375, 12.75, 107.0, 76.05029296875, 84.5, 118.60009765625, 109.5, 101.39990234375, 13.14990234375, 193.60009765625, 59.2998046875, 50.80029296875, 1.25, 16.44970703125, 28.14990234375, 21.85009765625, 22.2998046875, 127.900390625, 105.25, 4.150390625, 2.64990234375, 125.89990234375, 112.10009765625, 120.4501953125, 255.75, 107.35009765625, 75.849609375, 125.25, 87.60009765625, 19.39990234375, 45.7998046875, 10.0498046875, 143.849609375, 99.7998046875, 57.30029296875, 14.5, 203.9501953125, 48.05029296875, 85.85009765625, 37.19970703125, 31.5, 43.2001953125, 61.0, 84.39990234375, 25.5498046875, 4.849609375, 85.9501953125, 55.4501953125, 19.35009765625, 5.35009765625, 13.35009765625, 60.4501953125, 44.2998046875, 128.7998046875, 32.85009765625, 46.4501953125, 33.2001953125, 72.2998046875, 8.64990234375, 170.14990234375, 11.4501953125, 78.5, 19.75, 38.35009765625, 8.0498046875, 63.25, 7.7001953125, 37.150390625, 30.64990234375, 38.69970703125, 72.2998046875, 32.5, 22.10009765625, 145.44970703125, 58.5498046875, 72.5, 70.75, 49.75, 0.30029296875, 57.14990234375, 20.099609375, 28.349609375, 106.89990234375, 0.7998046875, 116.19970703125, 42.75, 18.9501953125, 80.0, 103.35009765625, 47.64990234375, 27.5, 15.25, 60.44970703125, 13.60009765625, 7.39990234375, 5.85009765625, 44.2001953125, ...)], dtype='object')] are in the [columns]"
​
Try:
data["True_Range"] = data[["High-Low","Close-low","Close-High"]].max(axis=1)
Instead of:
data["True_Range"] = data[[data["High-Low"], data["Close-low"],data["Close-High"]]].max(axis=1)
Your error signifies that you have input the data instead of the nested columnnames into your view of the dataframe, which produced the error.
Since the data from the columns themselves are not in the columnnames - you received the error.
One way of avoiding the error is:
data["True_Range"] = data[["High-Low", "Close-low", "Close-High"]].max(axis=1)

Syntax for interp2d or RectBivariateSpline

I have a data set of points, logR, logT, and logX, where X is a function of R and T. It's only a data set, I have no defined function for X. The data is listed in a table, where logR corresponds to columns and logT corresponds to logT. I am attempting to use an interpolation function to evaluate this grid at two inputs of logR and logT. I found my situation most related to this post:
How to pass arrays into Scipy Interpolate RectBivariateSpline?
But I could not arrange things so my function could be evaluated at my inputs. Here are my attempts:
import numpy as np
from scipy.interpolate import RectBivariateSpline, interp2d
op_r = np.array([1e-8, 3.1622e-8, 1e-7, 3.1622e-7, 1e-6, 3.1622e-6, 1e-5,
3.1622e-5, 1e-4, 3.1622e-4, 1e-3, 3.1622e-3, 1e-2, 3.1622e-2, 0.1, .31622, 1,
3.1622, 10])
op_T = np.array([17782.794, 19952.623, 22387.211, 25118.864, 28183.829,
31622.777, 35481.339, 39810.717, 44668.359, 50118.723, 56234.133, 63095.734,
79432.823, 89125.094])
log_op_val = np.array([[-0.598, -0.593, -0.583, -0.568, -0.539, -0.477,
-0.353, -0.142, 0.168, 0.558, 0.990, 1.443, 1.915, 2.407, 2.866, 3.239, 3.517,
3.725, 3.896], [-0.597, -0.592, -0.580, -0.561, -0.532, -0.474, -0.362,
-0.165, 0.138, 0.539, 1.001, 1.476, 1.942, 2.426, 2.912, 3.352, 3.702, 3.968,
4.175], [-0.588, -0.588, -0.578, -0.555, -0.520, -0.462, -0.357, -0.171,
0.124, 0.529, 1.009, 1.507, 2.001, 2.487, 2.979, 3.453, 3.856, 4.176, 4.422],
[-0.545, -0.559, -0.563, -0.546, -0.506, -0.442, -0.338, -0.159, 0.132, 0.538,
1.015, 1.525, 2.051, 2.565, 3.072, 3.563, 3.996, 4.356, 4.634], [-0.520,
-0.521, -0.519, -0.509, -0.475, -0.409, -0.301, -0.122, 0.167, 0.571, 1.052,
1.570, 2.106, 2.642, 3.176, 3.684, 4.136, 4.517, 4.822], [-0.518, -0.514,
-0.504, -0.478, -0.425, -0.344, -0.232, -0.056, 0.226, 0.629, 1.111, 1.631,
2.169, 2.719, 3.276, 3.804, 4.275, 4.672, 4.990], [-0.517, -0.513, -0.504,
-0.479, -0.417, -0.297, -0.129, 0.074, 0.353, 0.734, 1.202, 1.715, 2.250,
2.800, 3.364, 3.907, 4.394, 4.802, 5.127], [-0.518, -0.514, -0.505, -0.484,
-0.429, -0.311, -0.104, 0.185, 0.521, 0.894, 1.329, 1.818, 2.341, 2.883,
3.441, 3.986, 4.481, 4.894, 5.218], [-0.517, -0.514, -0.507, -0.490, -0.443,
-0.337, -0.142, 0.169, 0.588, 1.039, 1.480, 1.936, 2.431, 2.955, 3.496, 4.031,
4.521, 4.934, 5.253], [-0.516, -0.513, -0.507, -0.492, -0.453, -0.361, -0.184,
0.103, 0.510, 1.009, 1.531, 2.022, 2.502, 3.002, 3.519, 4.035, 4.513, 4.920,
5.235], [-0.515, -0.511, -0.506, -0.493, -0.460, -0.381, -0.225, 0.036, 0.409,
0.877, 1.415, 1.973, 2.502, 3.005, 3.505, 4.002, 4.468, 4.868, 5.183],
[-0.515, -0.511, -0.503, -0.490, -0.462, -0.394, -0.257, -0.022, 0.321, 0.759,
1.269, 1.827, 2.403, 2.949, 3.458, 3.948, 4.405, 4.802, 5.113], [-0.516,
-0.512, -0.502, -0.487, -0.460, -0.400, -0.279, -0.066, 0.254, 0.672, 1.164,
1.701, 2.278, 2.851, 3.388, 3.889, 4.347, 4.741, 5.047], [-0.517, -0.512,
-0.503, -0.485, -0.454, -0.397, -0.287, -0.092, 0.211, 0.620, 1.101, 1.628,
2.190, 2.762, 3.322, 3.841, 4.305, 4.695, 4.989], [-0.516, -0.512, -0.503,
-0.484, -0.449, -0.388, -0.283, -0.099, 0.192, 0.596, 1.071, 1.596, 2.148,
2.714, 3.281, 3.811, 4.280, 4.661, 4.937]])
T_1a = 22100.
R_a = rho_ta /(((T_1a)/(1e6))**3)
gri_chi_a = RectBivariateSpline(op_r, op_T, op_val)
chi_a = RectBivariateSpline(R_a, T_1a)
print chi_a
And this is the error I get:
Traceback (most recent call last):
File "model.py", line 279, in <module>
gri_chi_a = RectBivariateSpline(op_r, op_T, op_val)
"/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/interpolate/fitpack2.py", line 882, in __init__
raise TypeError('x dimension of z must have same number of '
TypeError: x dimension of z must have same number of elements as x
It is the same as if I use the interp2d function. Any help would be appreciated.
Copy-n-pasting your arrays I get:
In [391]: op_r.shape
Out[391]: (19,)
In [393]: op_T.shape
Out[393]: (14,)
In [395]: log_op_val.shape
Out[395]: (15, 19)
15 does not equal 14 or 19!

What's the correct way of using reduceByKey in Spark using Python

I'm new to apache spark and don't know if I'm misunderstanding reduceByKey or am encountering a bug. I'm using the spark-1.4.1-bin-hadoop1 build, due to
issues with the python Cassandra interface in spark-1.4.1-bin-hadoop2.
reduceByKey(lambda x,y: y[0]) returns the first value of the last tuple,
but reduceByKey(lambda x,y: x[0]) throws an exception.
Trying to get to reduceByKey(lambda x,y: x[0]+y[0]), to sum values by key, but that statement throws the same exception as x[0].
Code Fragments:
import sys
from pyspark import SparkContext, SparkConf
from pyspark import StorageLevel
from pyspark.sql import SQLContext, Row
from pyspark.sql.types import *
import h5py
import sys
import numpy
import os
import datetime
if __name__ == "__main__":
sc_conf = SparkConf().setAppName("VIIRS_QC").set("spark.default.parallelism", "49").set("spark.storage.memoryFraction", "0.75")
sc = SparkContext(conf=sc_conf)
sqlContext=SQLContext(sc)
f=h5py.File("/mnt/NAS/pmacharr/sample_20130918/GMTCO_npp_d20130919_t0544413_e0546054_b09816_c20130919063740340635_noaa_ops.h5", 'r')
result = f["/All_Data/VIIRS-MOD-GEO-TC_All/Latitude"]
myLats = numpy.ravel(result).tolist()
...
t1 = numpy.dstack((myLats, myLons, myArray, myM2_radiance, myDNP))
t1 = t1.tolist()
x=sc.parallelize(t1[0][123401:123410])
print t1[0][123401:123410]
print "input list=", t1[0][123401:123410]
y=x.map(
lambda (lat, lon, m6_rad, m2_rad, dn):
((round(lat,0),round(lon,0),dn), (m2_rad,m6_rad))
)
print "map"
print y.collect()
print "reduceByKey(lambda x,y: x)=", y.reduceByKey(lambda x,y: x ).collect()
print "reduceByKey(lambda x,y: y)=", y.reduceByKey(lambda x,y: y ).collect()
print "reduceByKey(lambda x,y: y[0])=", y.reduceByKey(lambda x,y: y[0]).collect()
print "reduceByKey(lambda x,y: x[0])=", y.reduceByKey(lambda x,y: x[0]).collect()
sc.stop()
exit()
Output:
./bin/spark-submit --driver-class-path ./lib/spark-examples-1.4.1-hadoop1.0.4.jar ./agg_v.py
input list= [
[12.095850944519043, 111.84786987304688, 41252.0, 7469.0, 16.0],
[12.094693183898926, 111.84053802490234, 40811.0, 7444.0, 16.0],
[12.093526840209961, 111.83319091796875, 40778.0, 7446.0, 16.0],
[12.092370986938477, 111.82584381103516, 39389.0, 7352.0, 16.0],
[12.091206550598145, 111.81849670410156, 42592.0, 7602.0, 16.0],
[12.09003734588623, 111.8111343383789, 38572.0, 7328.0, 16.0],
[12.088878631591797, 111.80377960205078, 46203.0, 7939.0, 16.0],
[12.087711334228516, 111.7964096069336, 42690.0, 7608.0, 16.0],
[12.08655071258545, 111.78905487060547, 40942.0, 7478.0, 16.0]
]
map=[
((12.0, 112.0, 16.0), (7469.0, 41252.0)),
((12.0, 112.0, 16.0), (7444.0, 40811.0)),
((12.0, 112.0, 16.0), (7446.0, 40778.0)),
((12.0, 112.0, 16.0), (7352.0, 39389.0)),
((12.0, 112.0, 16.0), (7602.0, 42592.0)),
((12.0, 112.0, 16.0), (7328.0, 38572.0)),
((12.0, 112.0, 16.0), (7939.0, 46203.0)),
((12.0, 112.0, 16.0), (7608.0, 42690.0)),
((12.0, 112.0, 16.0), (7478.0, 40942.0))
]
reduceByKey(lambda x,y: x)= [((12.0, 112.0, 16.0), (7469.0, 41252.0))]
reduceByKey(lambda x,y: y)= [((12.0, 112.0, 16.0), (7478.0, 40942.0))]
reduceByKey(lambda x,y: y[0])= [((12.0, 112.0, 16.0), 7478.0)]
reduceByKey(lambda x,y: x[0])=
15/09/24 12:02:39 ERROR Executor: Exception in task 14.0 in stage 8.0 (TID 406)
org.apache.spark.api.python.PythonException: Traceback (most recent call last):
File "/opt/apps/ots/spark-1.4.1-bin-hadoop1/python/lib/pyspark.zip/pyspark/worker.py", line 111, in main
process()
...
print "reduceByKey(lambda x,y: x[0])=", y.reduceByKey(lambda x,y: x[0]).collect()
TypeError: 'float' object has no attribute '__getitem__'
Using pyspark:
>>> t1=[
... [12.095850944519043, 111.84786987304688, 41252.0, 7469.0, 16.0],
... [12.094693183898926, 111.84053802490234, 40811.0, 7444.0, 16.0],
... ]
>>> t1
[[12.095850944519043, 111.84786987304688, 41252.0, 7469.0, 16.0],[12.094693183898926, 111.84053802490234, 40811.0, 7444.0, 16.0]]
>>> x=sc.parallelize(t1)
>>> y2=x.map(lambda (lat, lon, m6_rad, m2_rad, dn):((round(lat,0),round(lon,0),dn), (m6_rad, m2_rad)))
>>> y2.collect()
[((12.0, 112.0, 16.0), (41252.0, 7469.0)), ((12.0, 112.0, 16.0), (40811.0, 7444.0))]
>>> y2.reduceByKey(lambda (x), y: x[0]+y[0]).collect()
[((12.0, 112.0, 16.0), 82063.0)]
>>>
Or can do:
>>> y2.reduceByKey(lambda x, y: (x[0]+y[0], 0)).collect()
[((12.0, 112.0, 16.0), (82063.0, 0))]
>>> y2.reduceByKey(lambda x, y: (x[1]+y[1], 0)).collect()
[((12.0, 112.0, 16.0), (14913.0, 0))]
>>>
Not sure which is the"best" way, but its producing what I'm after.
Would it be "better" to implement the map differently?

Decimal error in list

I'm trying to input a csv file that I can then use to do calculations:
import csv
data=[]
file=input ("Enter file name: ")
with open(file,"r") as f:
reader=csv.reader(f)
for row in reader:
data.append([x.strip(";") for x in row])
print(data)
print("Calculate COV")
lst= data
spl= [x.split(";") for y in lst for x in y]
flattened = [float(x) for y in spl for x in y if x]
print (flattened)
But I keep getting this when I use decimal numbers:
[['13', '25;12', '97;13', '12;13', '47;13', '44;13', '09;12', '86;12', '78;12', '91;12', '93;12', '91;13', '11'], ['12', '92;13', '42;13', '58;13', '7;13', '62;13', '7;13', '31;12', '86;12', '59;12', '81;13', '46;12', '9'], ['13', '39;13', '5;13', '29;13', '26;13', '38;13', '45;13', '46;11', '95;12;12', '57;13', '22;12', '88'], ['12', '48;13', '76;13', '7;13', '77;13', '08;13', '48;13', '25;12', '31;12', '56;12', '56;12', '95;13', '38'], ['12', '52;14', '07;14', '46;14', '13;13', '98;14', '07;13', '92;12', '7;13', '01;12', '79;13;13', '13']]
When I should have this:
[13.25, 12.97, 13.12, 13.47, 13.44, 13.09, 12.86, 12.78, 12.91, 12.93, 12.91, 13.11, 12.92, 13.42, 13.58, 13.7, 13.62, 13.7, 13.31, 12.86, 12.59, 12.81, 13.46, 12.9, 13.39, 13.5, 13.29, 13.26, 13.38, 13.45, 13.46, 11.95, 12.57, 13.22, 12.88, 12.48, 13.76, 13.7, 13.77, 13.08, 13.48, 13.25, 12.31, 12.56, 12.56, 12.95, 13.38, 12.52, 14.07, 14.46, 14.13, 13.98, 14.07, 13.92, 12.7, 13.01, 12.79, 13.0, 13.13]
It's really not clear how you are trying to use the CSV module. First, by default, the csv module is going to use comma separated values, not semicolon separated values.
But either way, let's try writing some code:
import csv
class MyDialect(csv.excel):
delimiter = ';'
with open('in.csv', 'r') as f:
reader = csv.reader(f, MyDialect())
data = list(reader)
data = [[float(elem.replace(',', '.')) for elem in line] for line in data]
for line in data:
print line
in.csv
13,25;12,97;13,12;13,47;13,44;13,09;12,86;12,78;12,91;12,93;12,91;13,11
12,92;13,42;13,58;13,7;13,62;13,7;13,31;12,86;12,59;12,81;13,46;12,9
13,39;13,5;13,29;13,26;13,38;13,45;13,46;11,95;12;12,57;13,22;12,88
12,48;13,76;13,7;13,77;13,08;13,48;13,25;12,31;12,56;12,56;12,95;13,38
12,52;14,07;14,46;14,13;13,98;14,07;13,92;12,7;13,01;12,79;13;13,13
stdout
[13.25, 12.97, 13.12, 13.47, 13.44, 13.09, 12.86, 12.78, 12.91, 12.93, 12.91, 13.11]
[12.92, 13.42, 13.58, 13.7, 13.62, 13.7, 13.31, 12.86, 12.59, 12.81, 13.46, 12.9]
[13.39, 13.5, 13.29, 13.26, 13.38, 13.45, 13.46, 11.95, 12.0, 12.57, 13.22, 12.88]
[12.48, 13.76, 13.7, 13.77, 13.08, 13.48, 13.25, 12.31, 12.56, 12.56, 12.95, 13.38]
[12.52, 14.07, 14.46, 14.13, 13.98, 14.07, 13.92, 12.7, 13.01, 12.79, 13.0, 13.13]
Try this:
import csv
data=[]
import re
with open("out.csv","r") as f:
reader=csv.reader(f,delimiter=";")
for row in reader:
print row
data+=[x.split(",") for x in row]
print(data)
print("Calculate COV")
flattened = [float(x) for y in data for x in y]

'module' object has no attribute 'sim_pearson'

critics = {'Lisa Rose': {'Lady in the Water': 2.5, 'Snakes on a plane': 3.5, 'Just My Luck': 3.0,
'Superman Returns': 3.5, 'You, Me and Dupree': 2.5, 'The Night Listener': 3.0},
'Toby':{'Snakes on a Plane': 4.5, 'You, me and Dupreee': 1.0},
'Gene Seymour':{'Lady in the Water':3.0, 'Snakes on a plane': 3.5,'Just My Luck': 1.5,
'Superman Returns': 5.0,'You, Me and Dupree': 3.5, 'The Night Listener': 3.0}}
from math import sqrt
def sim_distance(person1, person2):
si={}
for item in prefs[person1]:
if item in prefs[person2]:
si[item]=1
if len[si]== 0: return 0
sum_of_squares=sum([pow[prefs[person1][item]-prefs[person2][item],2]
for item in prefes[person1] if item in prefs[person2]])
return 1/(1+sqrt(sum_of_squares))
>> import recommendations
>>recommendations.sim_distance(recommendations.critics, 'Lisa Rose', 'Gene Seymour')
Traceback(most recent call last):
File "<stdin>", line1, in?
AttributeError: 'module' object has no attribute 'sim_pearson'
Assuming the above code is in single file .
using command line:
1.open the command line
2.change the directory to the location where your python code is( use cd C:\user\Python27 or whatever your location is)
3.type python hit enter(it will start the console for python)
4.now type the following and hit enter after each line
from recommendations import critics
from recommendations import sim_distance
sim_distance(critics,'Lisa Rose','Gene Seymour')
Hope this will help to run your code

Categories

Resources