0
Python define dataframe object by using parameter
Is this possible? Like this: list=[âatopicâ,âbtopicâ,âctopicâ] for i in list: (Use the strings as the name of dataframe, to define three dataframe objects use the for loop) Thank you
1 Answer
0
You can do that like below,
import pandas as pd
import numpy as np
raw_data = {'first_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'last_name': ['Miller', 'Jacobson', 'Milner', 'Cooze', ""],
'age': [42, 52, 36, 24, 73],
'preTestScore': [4, 24, 31, "", "" ],
'postTestScore': ["25,000", "94,000", 57, 62, 70]}
l = ["atopic","btopic","ctopic"]
for i in range(len(l)):
l[i]= pd.DataFrame(raw_data, columns = ['first_name', 'last_name', 'age', 'preTestScore', 'postTestScore'])
print (l[0])
print (l[1])
print (l[2])