Я создал две серии, и я хочу создать третью серию, выполняя поэлементное умножение первых двух.Мой код приведен ниже:
new_samples = 10 # Number of samples in series
a = pd.Series([list(map(lambda x:x,np.linspace(2,2,new_samples)))],index=['Current'])
b = pd.Series([list(map(lambda x:x,np.linspace(10,0,new_samples)))],index=['Voltage'])
c = pd.Series([x*y for x,y in zip(a.tolist(),b.tolist())],index=['Power'])
Мой вывод:
TypeError: can't multiply sequence by non-int of type 'list'
Чтобы все было ясно, я вставляю свой фактический код for
, указанный ниже.Мой фрейм данных уже содержит три столбца Current
, Voltage
, Power
.Для моего требования я должен добавить новый список значений в существующие столбцы Voltage
, Current
.Но Power
значения создаются путем умножения уже созданных значений.Мой код приведен ниже:
for i,j in zip(IV_start_index,IV_start_index[1:]):
isc_act = module_allData_df['Current'].iloc[i:j-1].max()
isc_indx = module_allData_df['Current'].iloc[i:j-1].idxmax()
sample_count = int((j-i)/(module_allData_df['Voltage'].iloc[i]-module_allData_df['Voltage'].iloc[j-1]))
new_samples = int(sample_count * (module_allData_df['Voltage'].iloc[isc_indx]))
missing_current = pd.Series([list(map(lambda x:x,np.linspace(isc_act,isc_act,new_samples)))],index=['Current'])
missing_voltage = pd.Series([list(map(lambda x:x,np.linspace(module_allData_df['Voltage'].iloc[isc_indx],0,new_samples)))],index=['Voltage'])
print(missing_current.tolist()*missing_voltage.tolist())
Пример данных: module_allData_df.head ()
Voltage Current Power
0 33.009998 -0.004 -0.13204
1 33.009998 0.005 0.16505
2 32.970001 0.046 1.51662
3 32.950001 0.087 2.86665
4 32.919998 0.128 4.21376
Пример данных: module_allData_df.iloc [120: 126], и вам также требуется это
Voltage Current Power
120 0.980000 5.449 5.34002
121 0.920000 5.449 5.01308
122 0.860000 5.449 4.68614
123 0.790000 5.449 4.30471
124 33.110001 -0.004 -0.13244
125 33.110001 0.005 0.16555
пример данных: IV_start_index [: 5]
[0, 124, 251, 381, 512]
На основе ответа @jezrael
я успешно создал три отдельные серии.Как добавить их в основной фрейм данных.Мое требование объясняется в следующем сюжете.