Linked Questions
181 questions linked to/from How can you dynamically create variables?
0
votes
0
answers
30
views
How can I name mutiple dataframes separately generated inside a while loop [duplicate]
I have a while looping using a counter to generate separate dataframes based on a variable in a column.
As this is in a while loop the dataframe is reassigned to the same name which overwrites what ...
0
votes
0
answers
20
views
How to represent the name of a variable in batches in python? [duplicate]
I have many lists ,which are named like a+str(i), such as a0. I want to add the two adjacent ones in turn.
a0=['a']
a1=['k']
a2=['e','a']
a3=['k','e']
a0=a0+a1
a1=a1+a2
a2=a2+a3
I want to know ...
53
votes
7
answers
202k
views
Create multiple dataframes in loop
I have a list, with each entry being a company name
companies = ['AA', 'AAPL', 'BA', ....., 'YHOO']
I want to create a new dataframe for each entry in the list.
Something like
(pseudocode)
for c ...
2
votes
5
answers
17k
views
Python: Creating a number of lists depending on the count
Im trying to create a number of lists depending on the number in my header_count. The code below should generate 3 lists but i get a syntax error instead.
header_count = 4
for i in range(1, ...
3
votes
5
answers
1k
views
Pythonic ways to create independent lists from a list?
(I searched on this website + internet, but couldn't find an answer)
I am starting from:
myList = ['a', 'b', 'c']
And I want to get something pythonic equivalent of
a = []
b = []
c = []
or
a, b, c ...
0
votes
3
answers
44k
views
How to create variable names with a "for" loop? [duplicate]
I know my title may be somewhat confusing, but I had trouble describing my issue. Basically, I need to create a bunch of variables that all equal 0, and I want to do this with a for loop so I don't ...
0
votes
1
answer
6k
views
Creating classes inside a loop Python
I'm working on a Python project and I want to do something like the next example, but is incorrect. I need some help, please!
names = ['name1', 'name2']
for name in names:
class name:
[...
6
votes
2
answers
15k
views
How to get data from csv into a python object
I am a beginner python user. Having trouble getting data from csv into python in the required object format to satisfy a python function.
If I manually created the data in python (rather than bringing ...
2
votes
3
answers
6k
views
python - iterate through JSON list to match specific key value pair [duplicate]
I want to iterate through a JSON response to match specific key value pair to print it and another value in the same list.
The JSON looks like
[
{
"status": "ok",
"slot": null,
"name": "...
-1
votes
3
answers
4k
views
How can I generate random numbers and assign them to variables in python?
Suppose I want the variables a_1, a_2, a_3, a_4 to be random numbers from the uniform distribution U(0,100). I could write
import random
a_1 = random.uniform(0,100)
a_2 = random.uniform(0,100)
...
0
votes
3
answers
8k
views
Python creating variables with names from range [duplicate]
I want to use some code similar to what follows that actually works:
P = 20
n = 1
for x in range(1, P+1):
Ax = n #Hoping that you can name the variable from the current element in the range
n ...
3
votes
2
answers
4k
views
How to name dataframes in a for-loop? [duplicate]
I am attempting to name multiple dataframes using a variable in a for loop.
Here is what I tried:
for name in DF['names'].unique():
df_name = name + '_df'
df_name = DF.loc[DF['names'] == str(...
0
votes
2
answers
3k
views
Assigning a string (from a list of string) to a dataframe name pandas
I have a list of names, ['name1', 'name2',... 'nameN'], that I would like to use as names for the resulting dataframes after filtering the original dataframe by each name in a for loop
name1 = ...
0
votes
2
answers
8k
views
Create dataframe in a loop
I would like to create a dataframe in a loop and after use these dataframe in a loop. I tried eval() function but it didn't work.
For example :
for i in range(5):
df_i = df[(df.age == i)]
There ...
1
vote
3
answers
5k
views
Create variable from CSV
I want to make variables from a particular column in a CSV.
CSV will have the following headers:
FolderName,FolderManager,RoleGroup,ManagerEmail
Under FolderName will be a list of rows with ...