Python Forum
Creating a List with many variables in a simple way
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a List with many variables in a simple way
#1
Hi guys,

I am currently working on a regression task with python. My model contains 26 variables, 17 of them are dummy variables.
With that model I am trying to predict the dependent variable based on a MANUALLY inserted information. In other words I need a list which contains values for 26 variables so that the prediction can work. My problem is that I can't find an easy way to deal with the dummy variables.
My first bit of code looks like this and affects the non-dummy variables. I am ignoring syntax for now.

test = []
features1 = [ variable1, variable2, variable3, variable4, variable5, variable6, variable7, variable8, variable9 ]
for i in features1:
p = input('Enter: ' + str(i) + ' ' )
test.append(p)

this gives me a list something like this : test = [1, 2, 3, 4, 5, 6, 7, 8, 9]
The next 17 values can only be 0 or 1, since those are 2 dummy variables. So to be more precise , it has two ones and the rest are zeros.
Lets say for example the first dummy variable is about the weather. So it can be either :
sunny, cloudy, rainy, windy and foggy. If its cloudy the list would look like this : test = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 0, 0, 0]
If its foggy it would look like this test = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 1]
I would love to simply put in either weather condition and based on the input append the list accordingly.
E.g. the input would be : cloudy, and the code adds 0 , 1, 0, 0, 0 to the list. However I have no clue how this can be done with minimal amount of code. I am very thankful for any help and hope my question is clear!
Reply
#2
Don't worry about simplifying code that you have yet to make.
Start by writing something.
Surely, if you're working on a regression task you can take input and use a basic if tree to turn it into numeric data and add that to your list.
Do that and post your code, then people can help you to refine it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 179 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Advancing Through Variables In A List knight2000 0 520 May-13-2023, 03:30 AM
Last Post: knight2000
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,492 Jul-27-2022, 08:50 PM
Last Post: rob101
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,922 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Creating list of lists from generator object t4keheart 1 2,206 Nov-13-2020, 04:59 AM
Last Post: perfringo
  Creating a dictionary from a list Inkanus 5 3,166 Nov-06-2020, 06:11 PM
Last Post: DeaD_EyE
  Creating a list of dictionaries while iterating pythonnewbie138 6 3,278 Sep-27-2020, 08:23 PM
Last Post: pythonnewbie138
  Converting list to variables Palves 1 1,767 Sep-18-2020, 05:43 PM
Last Post: stullis
  Creating a variables inside FOR loop zazas321 5 4,106 Sep-16-2020, 04:42 PM
Last Post: Naheed
  Print variable values from a list of variables xnightwingx 3 2,639 Sep-01-2020, 02:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020