I have a dataframe with 60 columns of data (column 1 = I 1, column 2 = S 1.... column 3 = I 2, column 4 =S 2.. and so on)...
I want to create a function that selects two columns at a time for slicing, plotting and finding the integral of the slice. I can do this for two columns but I don't know how to implement a function to run all 60 columns. So far I have the following:
df = pd.DataFrame.from_csv(filepath, index_col =None)
df_slice =df.iloc[23500:25053]
R = df_slice['I 1']
I = df_slice['S 1']
rcParams['figure.figsize']= 10,5
plt.plot(R, I)
plt.xlabel('cm-1')
plt.ylabel('Hz')
#integration of peak
area = trapz(R)
print area
for the function:
def integrate_peak(filepath):
df = pd.DataFrame.from_csv(filepath, index_col =None)
for row in df:
..........slice
..........overlay plots
..........get integral for each plot curve
output:
30 integral answers in a separate dataframe
Any help would be appreciated.
EDIT:
I've tried this:
def get_slice():
df = pd.DataFrame.from_csv(filepath, index_col =None)
for i in range(1,31):
df_slice = df.iloc[23500:25053]
R = df_slice['I %i' %i]
I = df_slice['S %i' %i]
plt.plot(R,I)
area = trapz(R)
print area
get_slice()
This gives me an overlay of 30 plots, however gives me 30 values for integral (all being the same number)
Something like:
def f(col1,col2):
print col1,col2
R = df[col1]
I = df[col2]
rcParams['figure.figsize']= 10,5
plt.plot(R, I)
plt.xlabel('cm-1')
plt.ylabel('Hz')
area = np.trapz(R)
print area
return col2
reduce(lambda x,y:f(x,y),df)
plt.show()
For processing (col1,col2) then (col2,col3) and so on.
Alas, i have found the solution.
def get_slice():
area_list = []
df = pd.DataFrame.from_csv(filepath, index_col =None)
Raman = df['I 1']
Intensity = df['S 1']
for i in range(1,31):
df_slice = df.iloc[23500:25053]
R = df_slice['I %i' %i]
I = df_slice['S %i' %i]
for i in R:
area = trapz(R, x = I)
area_list.append(area)
a = np.mean(area_list)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.