I can't make a repeat Receive one row each in a data frame, perform an operation, and assign one to a new list

Asked 2 years ago, Updated 2 years ago, 82 views

I'm going to take one line from the data frame, calculate it, and assign it to the new list one by one.

If you look at it, only the number of rows 0 and 12 changes, but I don't know how to make it into a repeating sentence. There are up to 600 lines.

df1.iloc[0].to_list() ##Part to be modified
row0 = list(df1.iloc[0]) 
row0

row_sum = 0
for i in row0:
    row_sum += 10**(i/10)
row_sum = 10*np.log10(row_sum)
row_sum = round(row_sum, 2)
print(row_sum)

arr = []
arr.append(row_sum)

print(arr)
#----------------------------------------------------------
df1.iloc[1].to_list()
row1 = list(df1.iloc[1])
row1

for i in row1:
    row_sum += 10**(i/10)
row_sum = 10*np.log10(row_sum)
row_sum = round(row_sum, 2)
print(row_sum)

arr.append(row_sum)

print(arr)
#----------------------------------------------------------
df1.iloc[2].to_list()
row2 = list(df1.iloc[2])
row2

for i in row2:
    row_sum += 10**(i/10)
row_sum = 10*np.log10(row_sum)
row_sum = round(row_sum, 2)
print(row_sum)

arr.append(row_sum)

print(arr)

dataframe for

2022-09-20 08:58

1 Answers

I think we can do it mechanically. Check it out.

arr = []

for i in range(600):
    #df1.iloc[i].to_list()
    row = list(df1.iloc[i])
    #row1

    for e in row:
        row_sum += 10**(e/10)
    row_sum = 10*np.log10(row_sum)
    row_sum = round(row_sum, 2)
    print(row_sum)

    arr.append(row_sum)


2022-09-20 08:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.