pandas array of dataframes

Solutions on MaxInterview for pandas array of dataframes by the best coders in the world

showing results for - "pandas array of dataframes"
Charlotte
21 Feb 2018
1import datetime as dt 
2import numpy as np
3import pandas as pd
4
5dates_list = [dt.datetime(2015,11,i+1) for i in range(3)]
6month_day_list = [d.strftime("%m%d") for d in dates_list]
7
8dataframe_collection = {} # dictionary to store dataframes - generally better than an array
9
10for month_day in month_day_list:	# for each key
11  	# Create/ assign your new data:
12    new_data = np.random.rand(3,3)
13    # Store the new data in the dictionary:
14    dataframe_collection[month_day] = pd.DataFrame(new_data, columns=["one", "two", "three"])
15
16# Neat printing code:
17for key in dataframe_collection.keys():
18    print("\n" +"="*40)
19    print(key)
20    print("-"*40)
21    print(dataframe_collection[key])
22    
23#The code above prints out the following result:
24
25========================================
261102
27----------------------------------------
28        one       two     three
290  0.896120  0.742575  0.394026
301  0.414110  0.511570  0.268268
312  0.132031  0.142552  0.074510
32
33========================================
341103
35----------------------------------------
36        one       two     three
370  0.558303  0.259172  0.373240
381  0.726139  0.283530  0.378284
392  0.776430  0.243089  0.283144
40
41========================================
421101
43----------------------------------------
44        one       two     three
450  0.849145  0.198028  0.067342
461  0.620820  0.115759  0.809420
472  0.997878  0.884883  0.104158