I have multiple dataframe with number of rows that varies between 8,9,10. I want to take the dataframe with len 8,9 and add them rows of zeros - to make them with 10 rows also.
What is the best way to do so?
I have multiple dataframe with number of rows that varies between 8,9,10. I want to take the dataframe with len 8,9 and add them rows of zeros - to make them with 10 rows also.
What is the best way to do so?
Use DataFrame.reindex
in list comprehension:
dfs = [df1, df2, df3]
dfs = [x.reindex(range(10), fill_value=0) for x in dfs]
If need reindex by maximum index values create maximum length dynamically:
m = len(max(dfs, key=len))
dfs = [x.reindex(range(m), fill_value=0) for x in dfs]