I have a subset (type <class 'list'>) which contain many subdataframe(subset[0],subset[1],subset[2]......so on).I want to do some filtering on each subset and after filtering i want to append it to a new dataframe. My code:
new_df = pd.DataFrame()
for i in range(20):
a = subsets[i]
a = a[((a[f'RUT1_Ang_meas_{i}'] >= -1.047198) & (a[f'RUT1_Ang_meas_{i}'] <= 1.047198))]
.
.
#some filtering
.
.
new_df= pd.concat([a],axis=1)
new_df.info() ```
i am getting an empty final dataframe.
How can i modify the code ?
CodePudding user response:
Try this:
list1 = []
# inside the loop:
list1.append(a)
# after the loop
new_df = pd.concat(list1, axis=1)