i want the code code below only read the secoond line and only value of success in each…
- User
i want the code code below only read the secoond line and only value of success in each file : import pandas as pd import glob
Define the path where the Excel files are located
path = r'/root/SendPush/*.xlsx'
Create an empty list to store the sum of "Success" column in each file
success_sum_list = []
Loop through each Excel file in the directory
for file in glob.glob(path): # Read the Excel file into a Pandas DataFrame df = pd.read_excel(file)
# Sum the values in the "Success" column success_sum = df['Success'].sum() # Append the sum to the list success_sum_list.append(success_sum)Print the sum of "Success" column in each file
for i, sum in enumerate(success_sum_list): print(f'Sum of "Success" column in file {i+1}: {sum}')
sum = 0
for item in success_sum_list: sum += item print(f'Sum of Success : {sum} ')
- Assistant
You only want the code to read the second line and only the value of "success" in each file. Here's the modified code:
import pandas as pd import glob # Define the path where the Excel files are located path = r'/root/SendPush/*.xlsx' # Create an empty list to store the "Success" value in the second line of each file success_value_list = [] # Loop through each Excel file in the directory for file in glob.glob(path): # Read the Excel file into a Pandas DataFrame df = pd.read_excel(file) # Get the value in the "Success" column of the second row success_value = df.iloc[1]['Success'] # Append the value to the list success_value_list.append(success_value) # Print the "Success" value in the second line of each file for i, value in enumerate(success_value_list): print(f'Success value in file {i+1}, line 2: {value}')This code will only retrieve the value in the "Success" column of the second row in each Excel file.
- User
in the top code i want to sum all the value of each file at the end
- Assistant
To sum all the values in the "Success" column from each file at the end, you can modify the code as follows:
import pandas as pd import glob # Define the path where the Excel files are located path = r'/root/SendPush/*.xlsx' # Create an empty list to store the sum of "Success" column in each file success_sum_list = [] # Loop through each Excel file in the directory for file in glob.glob(path): # Read the Excel file into a Pandas DataFrame df = pd.read_excel(file) # Sum the values in the "Success" column success_sum = df['Success'].sum() # Append the sum to the list success_sum_list.append(success_sum) # Print the sum of "Success" column in each file for i, sum in enumerate(success_sum_list): print(f'Sum of "Success" column in file {i+1}: {sum}') # Calculate the overall sum of "Success" column overall_sum = sum(success_sum_list) print(f'Overall sum of "Success" column in all files: {overall_sum}')This code will compute the sum of the "Success" column from each file and store it in the
success_sum_list. Then, it will print the sum for each file and calculate the overall sum by summing all the values insuccess_sum_listand print it at the end.