The two list are:
lst1, lst2 = np.arange(301), 0.333 * np.arange(301)
First I created two data frames with 7 columns each from these lists.
arr1, arr2 = np.array_split(lst1, 7), np.array_split(lst2, 7)
df1 = DF(arr1).T
df2 = DF(arr2).T
Here, df1 and df2 each have 7 columns.
For example, df1 has following columns:
col0 = [0, 1, 2, 43]
col1 = [44,45,..,86]
col6 = [259,...,301]
data frame df2 also has also 7 columns.
The goal is to keep these 7 columns side to side in a large data frame.
The result should look like this:
Group Group ... Group
Galaxy Diff Galaxy Diff Galaxy Diff
0
1
2
................................
43
My attempt is this:
# Imports
import numpy as np
import pandas as pd
from pandas import DataFrame as DF
## Break the data
lst1, lst2 = np.arange(301), 0.333 * np.arange(301)
arr1, arr2 = np.array_split(lst1, 7), np.array_split(lst2, 7)
df1 = DF(arr1).T
df2 = DF(arr2).T
# Assign column names
clm = [ 'Group_%d'%i for i in range(len(arr1))]
df1.columns = clm
df2.columns = clm
# Make data type integer
#for i in range(df1.shape[1]):
#df1[i] = df1[i].astype(int)
df1.to_csv('tmp.txt',sep='\t')
df2.to_csv('tmp2.txt',sep='\t')
Problems
1. The numbers in df1 are floats they should be integers.
2. The numbers in df2 have so much precision, they shoud be %.3f format.
3. df1[i] = df1[i].astype(int)
command fails.
4. Also, df1 and df2 are two separate data frames, I want to make them a
single hierarchical dataframe with 7 columns each have two sub columns (namely, gal and diff) with corresponding values.
Some related links
https://chrisalbon.com/python/pandas_hierarchical_data.html
https://pandas.pydata.org/pandas-docs/stable/advanced.html
How to apply hierarchy or multi-index to panda columns
apply hierarchy or multi-index to panda columns
Pandas reset index on series to remove multiindex