python - Splitting dataframe column into equal windows in Pandas -


i have dataframe following , intend extract windows size = 30 , write loop each block of data , call other functions.

index = pd.date_range(start='2016-01-01', end='2016-04-01', freq='d') data = pd.dataframe(np.random.rand(len(index)), index = index, columns=['random']) 

i found following function, wonder if there more efficient way so.

def split(df, chunksize = 30):      listofdf = list()     numberchunks = len(df) // chunksize + 1     in range(numberchunks):         listofdf.append(df[i*chunksize:(i+1)*chunksize])     return listofdf  

you can use list comprehension. see so post how access dfs , way break dataframe.

n = 200000  #chunk row size list_df = [df[i:i+n] in range(0,df.shape[0],n)] 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -