保存文件为csv

import numpy as np
import os
import cv2
import csv
import matplotlib as plt
import random

from PIL import Image
import numpy as np
import pandas as pd

test = []  # this is a zhongjianshang

# 对txt文件的操作~
for line in open('new_truth.txt', 'r'):
    # print(type(line))
    x = line.split('\n')
    y = x[0].split(',')
    test.append(y)

# 遍历所有的图片
save = []
for i in range(len(test)):
    line = []

    line.append(test[i][0])

    y0 = int(test[i][2])
    y1 = int(test[i][4])
    x0 = int(test[i][1])
    x1 = int(test[i][3])
    box1 = [x0, y0, x1, y1]

    w = x1 - x0
    h = y1 - y0

    ares = w * h
    line.append(ares)

    save.append(line)

title=['name','areas']

x=pd.DataFrame(columns=title,data=save)
x.to_csv('./area.csv')


2、思考
这只是一个样例。

import pandas as pd

step1: 将一行数据保存在一个list中。
step2: 将所有的数据保存在另一个list中。所以变成了[[1,2],[3,4]]。
step3:取个title。
step4:

x=pd.DataFrame(columns=title,data=save)
x.to_csv('./area.csv')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值