我有一个这样的熊猫数据框
general_pd = pd.DataFrame(columns=['TimeStamp','C_strain_COY', 'C_strain_CUY', 'C_strain_ROX','C_strain_CUX', 'C_strain_CMX', 'C_strain_COX', 'C_strain_LOX', 'C_temp_CUY', 'C_temp_COY', 'C_temp_CUX', 'C_temp_CMX', 'C_temp_COX'])
我有几次点亮,基本上是14个传感器S1-到s14。 我试图将一个值附加到S的每一列,但得到空数据。
def process_sensor_list(dataframe, sensor, name):
for i in range(len(sensor)):
dataframe.loc[i] = (sensor[i])
process_sensor_list(general_pd, S1, 'C_strain_COY')
process_sensor_list(general_pd, S2, 'C_strain_CUY')
process_sensor_list(general_pd, S3, 'C_strain_ROX')
process_sensor_list(general_pd, S4, 'C_strain_CUX')
process_sensor_list(general_pd, S5, 'C_strain_CMX')
process_sensor_list(general_pd, S6, 'C_strain_COX')
process_sensor_list(general_pd, S7, 'C_strain_LOX')
process_sensor_list(general_pd, T1, 'C_temp_CUY')
process_sensor_list(general_pd, T2, 'C_temp_COY')
process_sensor_list(general_pd, T3, 'C_temp_CUX')
process_sensor_list(general_pd, T4, 'C_temp_CMX')
process_sensor_list(general_pd, T5, 'C_temp_COX')
答案 0 :(得分:0)
dataframe = dataframe.append({'TimeStamp' : 1 ,'C_strain_COY' : 2, 'C_strain_CUY' : 3, ... }, ignore_index=True)
如果要附加到现有列,只需将单个值的字典附加键即可。