[Solved] How can I ensure that my python Code Registers the row1 2 or 3 under a different segment of Code?

The problem is because you haven’t indented your code properly. Python code relies upon correct indentation to determine the order of processing for commands. Currently your code checks row1 value even if you didnt select row1, but you define row1 based on selecting it from the input. You need to indent the if statements under … Read more

[Solved] Django 1.11 – forms.Models: change default form widget for DateTimeField

Are you able to include any more of your code. i.e. Have you created a forms.py file? I presume you will be creating ModelForms? If you have you can do something like this: from django.forms import widget Class DateInput(forms.DateInput): input_type=”date” Class Example(models.ModelForm): class Meta: #insert class Meta below model = #reference your model fields = … Read more

[Solved] List contents changing with each iteration

I think your problem is in the last few lines: for i in range(len(tuples)): for x in range(len(tuples[i][1])): […] for neighbor in neighbors: for i in range(len(neighbor)-1): #<- HERE […] Your outer loop is iterating over the index of tuples and stores this index in the variable i. The nested loop at the end overwrites … Read more

[Solved] I’m getting an IndentationError. How do I fix it?

Why does indentation matter? In Python, indentation is used to delimit blocks of code. This is different from many other languages that use curly braces {} to delimit blocks such as Java, Javascript, and C. Because of this, Python users must pay close attention to when and how they indent their code because whitespace matters. … Read more

[Solved] Lists, conditionals and loops don’t give the result expected [closed]

This line: i = word.find(letter) always finds the first occurrence of letter in word, and this line: start = indeces.index(i) always finds the first occurrence of i in indeces. Then, this line: index=word.find(letter,start) includes start, so just finds the same letter straight away! The only way to make your current code work would be to … Read more

[Solved] Function should clean data to half the size, instead it enlarges it by an order of magnitude

When you merge your dataframes, you are doing a join on values that are not unique. When you are joining all these dataframes together, you are getting many matches. As you add more and more currencies you are getting something similar to a Cartesian product rather than a join. In the snippet below, I added … Read more

[Solved] How to split a list’s value into two lists [closed]

If you have it as datetimeobject: datos[‘day’] = dados[‘time’].dt.date datos[‘time’] = dados[‘time’].dt.time If you have it as string object: datos[‘day’] = dados[‘time’].str[:11] datos[‘time’] = dados[‘time’].str[11:] Or data[[‘day’, ‘time’]] = data[‘time’].str.split(‘ ‘).apply(pd.Series) data[[‘day’, ‘time’]] = data[‘time’].str.split(‘ ‘, expand=True) Or using regex data[[‘day’, ‘time’]] = data[‘time’].str.extract(‘(.*) (.*)’) To convert it to string: datos[‘time’] = dados[‘time’].astype(str) It is … Read more

[Solved] Predicting numerical features based on string features using sk-learn

Below is tested and fully working code of yours: data_train = pd.read_csv(r”train.csv”) data_test = pd.read_csv(r”test.csv”) columns = [‘Id’, ‘HomeTeam’, ‘AwayTeam’, ‘Full_Time_Home_Goals’] col = [‘Id’, ‘HomeTeam’, ‘AwayTeam’] data_test = data_test[col] data_train = data_train[columns] data_train = data_train.dropna() data_test = data_test.dropna() data_train[‘Full_Time_Home_Goals’] = data_train[‘Full_Time_Home_Goals’].astype(int) from sklearn import preprocessing def encode_features(df_train, df_test): features = [‘HomeTeam’, ‘AwayTeam’] df_combined = pd.concat([df_train[features], … Read more