Jan-02-2021, 05:03 AM
A .csv file is a text file.
Something has to tell the csv reader what belongs in what column.
Below, the separator is a comma.
The comma was put there when I saved a Libre Office spreadsheet as .csv
Here is a peek:
When I open this .csv file with Libre Office, LO looks for the separator. Can be tab, comma, dunno what.
This reads the above file and also can save the data I want, better than csv.reader() (I think):
Something has to tell the csv reader what belongs in what column.
Below, the separator is a comma.
The comma was put there when I saved a Libre Office spreadsheet as .csv
Here is a peek:
Quote:Photo,phone,number,name,attendance,attn%,Final Score,points%,points,hwW16,cwW16,Week 16,hwW15,cwW15,Week 15,hwW14,cwW14,Week 14,hwW13,cwW13,Week 13,hwW12,cwW12,Week 12,hwW11,cwW11,Week 11,hwW10,cwW10,Week 10,hwW9,cwW9,Week 9
,,,,max Attendance,,,Max Score,425,,,,50,25,,50,25,,50,25,,50,25,,50,25,,0,25,,0,25,
,,,23名,8,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Photo,phone,学号,姓名,出勤,出勤率,期末分数,得分率,得分,HW,CW,Week 16,HW,CW,Week 15,HW,CW,Week 14,HW,CW,Week 13,HW,CW,Week 12,HW,CW,Week 11,HW,CW,Week 10,HW,CW,Week 9
,,1921030146,聂林,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,,1921090147,郜阳杰,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,,1922190144,汪毓韬,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,,1923010312,张长乐,7,100,100,100,425,,,1,50,25,1,50,25,1,50,25,1,50,25,1,50,25,1,0,25,1,0,25,1
When I open this .csv file with Libre Office, LO looks for the separator. Can be tab, comma, dunno what.
This reads the above file and also can save the data I want, better than csv.reader() (I think):
import pandas as pd # Read the file file1 = '/home/pedro/winter2020/20PY/dumpFiles/attendanceWinter2020_20PYlatestPyMade_test1.csv' dg = pd.read_csv(file1, usecols=['number', 'name', 'Final Score']) # write the file file2 = '/home/pedro/winter2020/20PY/dumpFiles/panda_bear.csv' dg.to_csv(file2, encoding='utf8', index=False, sep=',')