'How to append many range of subset to a new dataframe after some filtering?
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 ?
Solution 1:[1]
Try this:
list1 = []
# inside the loop:
list1.append(a)
# after the loop
new_df = pd.concat(list1, axis=1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | J Foley |
