Answer the question
In order to leave comments, you need to log in
How to remove last rows in matrix from csv file?
There are three codes, one is the main one, which executes the others, the codes read the matrix from one csv file, delete the last 4 lines and write a new matrix (without the last 4 lines) to a new csv file. Tell me how to do so that the lines are deleted
Here is the main code:
import matrixfile as mf
import matrixziro as mz
from matplotlib.pyplot import matshow, show
mzr = mz.GetZiroMatrix(mf.GetMatrix('tekst.csv'))
mf.SaveMatrix(mzr, 'resultat_2.csv')
matshow(mzr)
show()
def GetZiroMatrix(mt):
return [len(m) - 1], m[0] = m[0],len(m) - 1]* len(row) for row in mt] #не работающая функция,оператор должен остаться обязательно
import csv
def GetMatrix(filename):
return [[int(token) for token in line.split()] for line in open(filename)]
def SaveMatrix(mt, filename):
with open(filename, 'w') as f:
for row in mt:
print(' '.join(map(repr, row)), file=f)
Answer the question
In order to leave comments, you need to log in
Why are you inventing bicycles?
with open('input.csv', 'r') as fi, open('output.csv', 'w') as fo:
print(*fi.readlines()[:-4], file=fo, sep='')
import pandas a pd
pd.read_csv(..., skipfooter=4).to_csv(...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question