[Solved] How come python did not refer to this very simple scenario? [closed]

Check out virtualenv and virtualenvwrapper. Like maven, these are third-party projects and not part of the language distribution itself. I have no idea what maven does exactly, so I can’t say for sure whether virtualenv is directly equivalent. It’s mainly intended for development and testing environments. 1 solved How come python did not refer to … Read more

[Solved] different between append list to array python [closed]

They only reason to use method two is because you want to create a copy of arr2. Changes to the copy would not affect the original. Python 3.6.8 (default, Feb 14 2019, 22:09:48) [GCC 7.4.0] on cygwin Type “help”, “copyright”, “credits” or “license” for more information. >>> arr1 = [] >>> arr2 = [1,2,3,4,5] >>> … Read more

[Solved] How to find profit or loss percentage from consecutive rows [closed]

df = pd.DataFrame() df[‘Date’] = [‘2017-05-20’, ‘2017-05-20’, ‘2017-05-20’] df[‘Price’] = [50, 60, 45] df[‘Prof/Loss’] = (df[‘Price’] / df[‘Price’].shift())*100 – 100 First, I think your math for calculating the Loss/Profit was wrong, I hope I fixed that for you. Second, you can use the .shift() method to get the previous row, use .shift(-1) to get the … Read more

[Solved] I have python syntax error in django project

You are making mistake here user = User.objects.create_user{ username=request.POST[“username”], password = request.POST[“password”] Try this user = User.objects.create_user(username=request.POST[“username”],password = request.POST[“password”]) 2 solved I have python syntax error in django project

[Solved] Python List parsing (incude int, str)

This is the way to go: x = [‘2’, ‘3/4’, ‘+’, ‘4’, ‘3/5’] g = [] for i in x: try: g.append(int(i)) except ValueError: pass print(g) # [2, 4] What you tried is not a try-except block. It is an if statement which failed because ‘4’ is not an int instance (4 is, notice the … Read more

[Solved] Basic Python 2.7 Math Script (4 variables and 3 consecutive math operations) [closed]

If I understand the problem correctly, I would ask a user what operation he wants to go with: math_option =raw_input(‘Choose the math operation: ‘) and later on check what option was chosen: if math_option == “add”: print add(x, y) if math_option == “multiply”: add_num = add(x,y) mul_num = multiply(math_option,z) print mul_num and so on 1 … Read more

[Solved] Python if elif code

It’s because the input() function takes string input. Either convert the input into int using int() function OR if x == ‘1’: # your stuffs elif x == ‘2’: # your stuffs The problem is your last condition: elif >=0 because no matter which integer I type it’s always greater than 0 isn’t it? Thus, … Read more

[Solved] Python returns “SyntaxError: invalid syntax sys module” [closed]

import pandas as pd sys.path.insert(0, “/usr/lib/python2.7/site-packages”) This line contains two statements. Split them into two lines: import pandas as pd sys.path.insert(0, “/usr/lib/python2.7/site-packages”) Or, if they must be in one line, separate them with semicolon (highly not recomended!!!): import pandas as pd; sys.path.insert(0, “/usr/lib/python2.7/site-packages”) 1 solved Python returns “SyntaxError: invalid syntax sys module” [closed]

[Solved] converting a text file to csv file with out index

Try this: from io import StringIO csvtext = StringIO(“””1 1 1 1 1 2 3 4 4 4 4″””) data = pd.read_csv(csvtext, sep=’\n’, header=None) data.to_csv(‘out.csv’, index=False, header=False) #on windows !type out.csv Output: 1 1 1 1 1 2 3 4 4 4 4 2 solved converting a text file to csv file with out index

[Solved] How many times words (from list) do occur in string [python]

If you want to check for substrings also i.e azy in lazy, you need to check each word from words is in each substring of message: message = “The quick brown fox jumps over the lazy dog” words = [“the”,”over”,”azy”,”dog”] print(sum(s in word for word in set(message.lower().split()) for s in words)) 4 Or simply check … Read more

[Solved] Why we need to install virtualenv and virtualenvwrapper

Going through the comments and answers I came to conclution that- At first we have to install virtual environment to isolate my project settings from system’s settings. Here settings refer to Various packages with different versions. This isolation helps to prevent any conflict between systems setting and projects settings. Also there can be multiple projects. … Read more

[Solved] Finding consecutive letters in a list [closed]

def consecutiveLetters(word): currentMaxCount = 1 maxChar=”” tempCount = 1 for i in range(0, len(word) – 2): if(word[i] == word[i+1]): tempCount += 1 if tempCount > currentMaxCount: currentMaxCount = tempCount maxChar = word[i] else: currentMaxCount = 1 return [maxChar,tempCount] result = consecutiveLetters(“TATAAAAAAATGACA”) print(“The max consecutive letter is “, result[0] , ” that appears “, result[1], ” … Read more

[Solved] Feching user’s current location tips [closed]

So you really have two options. The first, and most likely to be accurate, is to ask the user through their browser via javascript, what their location is. HTML5 allows you to do this through geolocation: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation The basics are as follows: navigator.geolocation.getCurrentPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude); }); Obviously, this requires the user to agree to … Read more