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
最新推荐文章于 2025-04-07 09:19:32 发布
文章描述了一个Python程序,使用pandas库读取CSV文件,提取名为Unnamed:3列中的Mean子序列,并将这些子序列转置后写入新的CSV文件。
3万+

被折叠的 条评论
为什么被折叠?



