I want to make a pandas Dataframe
with following columns.
my_cols = ['chrom', 'len_of_PIs']
and following values inside specific columns:
chrom = pd.Series(['chr1', 'chr2', 'chr3'])
len_of_PIs = pd.Series([[np.random.randint(15, 59, 86)],
[np.random.randint(18, 55, 92)],
[np.random.randint(25, 61, 98)]])
I am expecting the output simply like:
chrom len_PIs
chr1 49, 32, 30, 27, 52, 52,.....
chr2 27, 20, 40, 41, 44, 50,.....
chr3 35, 45, 56, 42, 58, 50,.....
where, the len_PIs
can be a list
or str
, so I can do easy downstream analyses. But, I am not getting the data as expected when I do:
new_df = pd.DataFrame()
new_df['chrom'] = chrom
# this code is giving me an output like
new_df['len_PIs'] = len_of_PIs.astype(str)
chrom len_PIs
0 chr1 [array([49, 32, 30, 27, 52, 52, 33, 51, 36, 47, 34, ...
1 chr2 [array([27, 20, 40, 41, 44, 50, 40, 34, 36, 33, 23, ...
2 chr3 [array([35, 45, 56, 42, 58, 50, 42, 27, 53, 57, 40, ...
# and each one of these below codes are giving me an output like
new_df['len_PIs'] = len_of_PIs.as_matrix()
new_df.insert(loc=1, value=len_of_PIs.astype(list) , column='len_PIs')
new_df['len_PIs'] = pd.DataFrame(len_of_PIs, columns=['len_PIs'], index=len_of_PIs.index)
chrom len_PIs
0 chr1 [[49, 32, 30, 27, 52, 52, 33, 51, 36, 47, 34, ...
1 chr2 [[27, 20, 40, 41, 44, 50, 40, 34, 36, 33, 23, ...
2 chr3 [[35, 45, 56, 42, 58, 50, 42, 27, 53, 57, 40, ...
How can I update this method? If there are alternate and comprehensive method from beginning of column and data prepration
that would be nice too.