#读txt写csv
import pandas as pd
list1 = []
list2 = []
try:
file = open('two_train_xin.txt', 'r')
except FileNotFoundError:
print('File is not found')
else:
lines = file.readlines()
for line in lines:
a = line.split()
x = a[0]
y = a[1]
list1.append(x)
list2.append(y)
file.close()
for x in list1:
print(x)
print(list1)
print(list2)
dataframe = pd.DataFrame({'label_y':list1,'image_name':list2})
#将DataFrame存储为csv,index表示是否显示行名,default=True
dataframe.to_csv("two_train_xin.csv",index=False,sep=',',header = 0)
读取txt并写入csv
于 2023-06-04 22:17:23 首次发布