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

20th Mar 2018, 4:27 PM
ChrisAnn
ChrisAnn - avatar
1 Odpowiedź
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])
20th May 2018, 10:42 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar