在数据帧rebinnedDF
中,我想添加另一列具有重复随机行值的列。我将该值创建为repeateArray
。
year2014_bin year2015_bin year2016_bin year2017_bin
0 binZ binZ binZ binZ
1 binZ binZ binZ binZ
repeateArray=[x for x in range (0, rebinnedDF.shape[0]/len(rebinnedDF.columns))]
repeateArray =rebinnedDF.join(pd.DataFrame (repeateArray))
当我执行repeateArray[0][:2]
(这是添加的列)时,我得到nan
。不应基于上面的列表理解而重视。
year2014_bin year2015_bin year2016_bin year2017_bin 0
0 binZ binZ binZ binZ nan
1 binZ binZ binZ binZ nan
4 binZ binZ binZ binZ nan
5 binZ binZ binZ binZ nan
6 binZ binZ binZ binZ nan
7 binZ binZ binZ binZ nan
8 binZ binZ binZ binZ nan
9 binZ binZ binZ binZ nan
Desired. I want `0` to be randomly repeated based on the length of the dataframe. I have 6 million rows. Number of repetition really does not matter.
year2014_bin year2015_bin year2016_bin year2017_bin 0
0 binZ binZ binZ binZ 1
1 binZ binZ binZ binZ 2
2 binZ binZ binZ binZ 3
3 binZ binZ binZ binZ 4
4 binZ binZ binZ binZ 1
.............