Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas array of dataframes

import datetime as dt 
import numpy as np
import pandas as pd

dates_list = [dt.datetime(2015,11,i+1) for i in range(3)]
month_day_list = [d.strftime("%m%d") for d in dates_list]

dataframe_collection = {} # dictionary to store dataframes - generally better than an array

for month_day in month_day_list:	# for each key
  	# Create/ assign your new data:
    new_data = np.random.rand(3,3)
    # Store the new data in the dictionary:
    dataframe_collection[month_day] = pd.DataFrame(new_data, columns=["one", "two", "three"])

# Neat printing code:
for key in dataframe_collection.keys():
    print("
" +"="*40)
    print(key)
    print("-"*40)
    print(dataframe_collection[key])
    
#The code above prints out the following result:

========================================
1102
----------------------------------------
        one       two     three
0  0.896120  0.742575  0.394026
1  0.414110  0.511570  0.268268
2  0.132031  0.142552  0.074510

========================================
1103
----------------------------------------
        one       two     three
0  0.558303  0.259172  0.373240
1  0.726139  0.283530  0.378284
2  0.776430  0.243089  0.283144

========================================
1101
----------------------------------------
        one       two     three
0  0.849145  0.198028  0.067342
1  0.620820  0.115759  0.809420
2  0.997878  0.884883  0.104158
Comment

PREVIOUS NEXT
Code Example
Python :: dobj in spacy 
Python :: python print main arguments 
Python :: how to skip error python 
Python :: access icloud doc on jupyter notebook 
Python :: pandas series create 
Python :: how to make a bot send whatever you dm it into a server discord.py 
Python :: python sum certain postions of array 
Python :: __floordiv__ 
Python :: python append to a exiting csv file 
Python :: python sort() and sorted() 
Python :: how to encrypt and decrypt strings python 
Python :: min stack in python 
Python :: change index function for class python 
Python :: np append 
Python :: python add column to a matrix 
Python :: retrieve content inside the meta tag python 
Python :: how to add user input for a question python 
Python :: figure in matplotlib 
Python :: includes python 
Python :: python pip past 
Python :: random number list 
Python :: programmer tool 
Python :: python can you put try except in list comprehension 
Python :: python function 
Python :: tkinter window minsize 
Python :: python list sum 
Python :: get last x elements of list python 
Python :: how to pass csrf token in post request django 
Python :: Run a Flask API from CMD 
Python :: shared SHMEM python 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =