import pandas as pd
import csv
import numpy as np
import itertools
# 读取原始CSV文件
df = pd.read_csv('c.csv')
# 提取"Unnamed: 3"列
df = df['Unnamed: 3'].tolist()
data = df
# print(df)
results = []
current_idx = 0
# with open('output.csv', 'w', newline='') as csvfile:
# writer = csv.writer(csvfile)
#
# for i, item in enumerate(data):
# if item == 'Mean':
# start_index = i + 1
# end_index = min(i + 151, len(data))
#
# extracted_strings = data[start_index:end_index]
#
# if extracted_strings: # 如果成功提取到了至少一个字符串
# writer.writerow(extracted_strings)
# current_idx += 1
#
# else: # 若未能提取到足够的字符串,可以选择记录或跳过
# pass # 可在此处添加日志记录或其他处理方式
#
# # 关闭文件
# csvfile.close()
for i, item in enumerate(data):
if item == 'Mean':
start_index = i + 1
end_index = min(i + 151, len(data))
extracted_strings = data[start_index:end_index]
if extracted_strings:
results.append(extracted_strings)
# 对结果进行转置
transposed_results = list(zip(*results))
# 打开并写入CSV文件
with open('output_transposed.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# 写入转置后的每一列
for column in transposed_results:
writer.writerow(column)
# 关闭文件
csvfile.close()
提取ENVI ROI statistics中的每个波段的Mean
最新推荐文章于 2024-09-09 00:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)