I initialize a list of length n using df_list = [None] * n
. Then I have a for loop where I fill each element of df_list
with a dataframe. Then, when I concat all these dataframes together using df = pd.concat(df_list, axis=0)
I end up with fewer rows than expected, and upon further inspection I find that some elements of df_list
are None
type while others are dataframes. This is strange to me because in my for loop, I print the type of each value before filling it into df_list
and they are all dataframes of the desired shape and columns as well.
Wondering how, after running the loop, I can have None
values in df_list
when each value I filled in is a dataframe and not None
.
Any help here is appreciated - quite puzzled by this!
Why do you even need to initialize the list with None values. Just create empty list and append your dataframes to it.