concentration_list = ['saline0.05%', 'saline0.10%', 'saline0.20%', 'saline0.30%', 'saline0.40%', 'saline0.50%']
df_saline_median = pd.DataFrame(columns=['1kHz_mag','2kHz_mag','3kHz_mag','7kHz_mag','11kHz_mag','17kHz_mag',
                                         '23kHz_mag','31kHz_mag','43kHz_mag','61kHz_mag','89kHz_mag','127kHz_mag',
                                         '179kHz_mag','251kHz_mag','349kHz_mag'])

for i in concentration_list:
    saline_group = df[df['name'] == i]
    saline_median = saline_group[['1kHz_mag','2kHz_mag','3kHz_mag','7kHz_mag','11kHz_mag','17kHz_mag',
                                  '23kHz_mag','31kHz_mag','43kHz_mag','61kHz_mag','89kHz_mag','127kHz_mag',
                                  '179kHz_mag','251kHz_mag','349kHz_mag']].median()
    df_saline_median.loc[i] = saline_median
print(df_saline_median)

This code snippet uses the Python Pandas library to calculate the median values of different frequency magnitudes for various saline concentrations. The code first defines a list of saline concentrations and then creates an empty Pandas DataFrame with the frequency columns. Then, the code iterates through the list of concentrations and filters the original DataFrame to select data for the current concentration. For each concentration, the code calculates the median value for each frequency column and stores it in the df_saline_median DataFrame. Finally, the code prints the DataFrame containing the median values for each concentration across all frequencies.

Python Pandas: Calculate Median Values for Different Saline Concentrations

原文地址: https://www.cveoy.top/t/topic/jFRw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录