I want to get one table out of the while
loop instead of multiple tables. I have tried to merge the dataframes, but that only gives multiple tables with 2 rows and not 1 big table with all data. The while
loop is used to get the data from each sensor and this data needs to get displayed in one table.
I tried to merge the data in different ways like df.merge
and also used other statements to get the data like the if/else and the for statement. The closest I came to the wanted result was using the while statement and combining the results via pd.concat
. This gave me tables of 2 rows but not the wanted table with all the results.
The dimensions in both dataframes is the same. The dataframes are made using this:
d = {
"name": [loc_name],
"onder(<"+ str(CO2_low)+ "ppm)": [lessperc],
"tussen("+str(CO2_low)+"-"+str(CO2_high)+"ppm)": [betweenperc],
"boven(>"+ str(CO2_high)+"ppm)": [moreperc]
}
dummy data before a dataframe is made so this is d in my code:
{'name': ['1.04'], 'onder(<950ppm)': [1.0], 'tussen(950-1100ppm)': [0.0], 'boven(>1100ppm)': [0.0]}
{'name': ['1.05'], 'onder(<950ppm)': [0.98], 'tussen(950-1100ppm)': [0.2], 'boven(>1100ppm)': [0.0]}
{'name': ['1.06'], 'onder(<950ppm)': [0.93], 'tussen(950-1100ppm)': [0.4], 'boven(>1100ppm)': [0.3]}
Here is an example of the wanted result:
Name | <950 | 950-1100 | >1100 |
---|---|---|---|
1.04 | 1.0 | 0.0 | 0.0 |
1.05 | 0.98 | 0.2 | 0.0 |
1.06 | 0.93 | 0.4 | 0.3 |
Code I am currently using:
#Create the dataframe
while(k==0):
k = k + 1
#d is used to get the data from the sensors
d = (sensordata)
df1 = pd.DataFrame(data=d)
#Add rows for the next sensor/location
else:
d = (sensordata)
df2 = pd.DataFrame(data=d)
frames = [df1, df2]
result = pd.concat(frames)
print(result)