How to ignore first two columns of CSV file

pandas read_csv skip columns
read.csv skip first column r
read csv skip columns pandas
how to skip first column in csv python
pandas read_csv dtype
read first column of csv python pandas
pandas read_csv set column names
csv skip rows python

I'm trying to read a .csv file, that contains students names, students IDs, and many columns of grades and use that information to write lines in a listbox that look like this John --> 12345 --> 89.50, where the first value is student name, the second value is student id, and the third value is an average of the test scores.

I'm able to read the file and assign token[0] to name and token1 to ID, I just can't figure out how to get the remain values (grades) from a string to a double, so that I can do the math to get the averages.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace McKensey
{
    //struct for students name, ID, grades
    struct Student
    {
        public string name;
        public string ID;
        public string grade;
    }

    public partial class Form1 : Form
    {
        //feild to hold a list of GradeEntry
        private List<Student> gradeList = new List<Student>();

        public Form1()
        {
            InitializeComponent();
        }

        //the ReadFile method reads thecontents of the .csv test and stores
        //it as Student objects in gradeList
        private void ReadFile()
        {
            StreamReader inputFile;     //to read the file
            string line;                //to hold a line from the file
            double grade;
            double total = 0;

            //creat a instance of the Student structure
            Student entry = new Student();

            //create a delimiter array
            char[] delim = { ',' };

            //open the .csv file
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                //open the selected file
                inputFile = File.OpenText(openFile.FileName);

                //read the files data
                while (!inputFile.EndOfStream)
                {
                    //read the lines from the file
                    while (!inputFile.EndOfStream)
                    {
                        line = inputFile.ReadLine();

                        //tokenize the line
                        string[] tokens = line.Split(delim);

                        entry.name = tokens[0];
                        entry.ID = tokens[1];



                        gradeList.Add(entry);

                    }


                }
                //close file
                inputFile.Close();
            }
            else
            {
                MessageBox.Show("Opertaion Canceled.");
            }
        }
        private void DisplayInfo()
        {
            foreach (Student entry in gradeList)
            {

                listBox1.Items.Add(entry.name + "-->" + entry.ID + "-->" + entry.grade);
            }
        }


        private void processButton_Click(object sender, EventArgs e)
        {
            ReadFile();
            DisplayInfo();
        }
    }
}

You can simply do this:

IEnumerable<string> strCSV =
            File.ReadLines(@"C:\\Users\\xxx\\Desktop\\Book1.csv");

var results = from str in strCSV
            let tmp = str.Split(',')
                .Skip(2)  // skip the first two columns
                .Select(q => Convert.ToInt32(q))
            select new
            {
                Max = tmp.Max(),
                Min = tmp.Min(),
                Total = tmp.Sum(),
                Avg = tmp.Average()
            };

        var query = results.ToList();

        foreach (var q in query)
        {
            Console.WriteLine(
                string.Format("Maximum: {0}, " +
                              "Minimum: {1}, " +
                              "Total: {2}, " +
                              "Average: {3}",
                    q.Max, q.Min, q.Total, q.Avg));
        }

How to ignore first two columns of CSV file, Note: index_col=False can be used to force pandas to not use the first column as the index, e.g. when you If True and parse_dates specifies combining multiple columns then keep the original columns. If you want the rest from Double into String then you can do it something like: entry. grade = double. I have an ascii dataset which consists of three columns, but only the last two are actual data. Now I want to create a dotchart of the data by using read.csv(file = "result1", sep= " ") . R reads all three columns.

How read a CSV file skipping the first column using python, To skip the first column: $ printf 'foo,bar\n1,2\n' > test.csv >>> import csv >>> with open('test.csv') as fin: reader = csv.reader(fin) for row in  Open CSV file in Excel. The most usually used method must be opening CSV file directly through Excel. 1. Click File > Open > Browse to select a CSV file from a folder, remember to choose All Files in the drop-down list next to File name box. See screenshot: 2. Click Open, and the CSV file has been opened in the Excel. Tip.

If you want the rest from Double into String then you can do it something like:

 entry.grade = double.Parse(tokens[2]).ToString() + ',' + double.Parse(tokens[3]).ToString() + ',' + double.Parse(tokens[4]).ToString() + ',' + double.Parse(tokens[5]).ToString() + ',' + double.Parse(tokens[6]).ToString();

You can wrap it with try catch if you want to handle the error.

How to read data using pandas read_csv, pandas read_csv assigning row labels using multiple column names or index To skip reading the first 4 rows from this csv file, you can use  When I compare the two files how can I specify that I want to ignore column 3 (GMTOffset) when doing the comparison. Problem 2: When I compare the two files how can I specify to ignore seconds field i.e. in column 2 of csv file ignore the 3rd field in the value which is seperated by ':'. Or something along that sort.

how to read CSV file in matlab while ignoring the first line, how to read CSV file in matlab while ignoring the first line hi i have this csv file with one header that i dont need and two columns of numbser that i need:  I'm trying to read a .csv file, that contains students names, students IDs, and many columns of grades and use that information to write lines in a listbox that look like this John --> 12345 --> 89.50, where the first value is student name, the second value is student id, and the third value is an average of the test scores.

Pandas : skip rows while reading csv file to a Dataframe using , So, if our csv file has header row and we want to skip first 2 data rows is multiple of 3 i.e. skip every 3rd line while reading csv file and loading  You don't need to ignore the first column specifically, you just need to query the relevant column of the data table. i.e.: print all rows of the dataframe where column X =< 0 && X >= 1.

pandas.read_table, A local file could be: file://localhost/path/to/table.csv. Note that regex delimiters are prone to ignoring quoted data. Note: index_col=False can be used to force pandas to not use the first column as the index, e.g. when you If True and parse_dates specifies combining multiple columns then keep the original columns. The preferred method for skipping a column involves the following three steps: First, delete any format-file row that describes a field that is missing from the source data file. Then, reduce the "Host file field order" value of each format-file row that follows a deleted row.

Comments
  • Please can you show your CSV file data? Also, is this question actually about ignoring the first 2 columns, or is it about parsing a string to a double?
  • So is your question about ignoring columns or converting string to double?
  • I'm not sure :/ if there is a way to convert only the grade columns of the CSV I guess I that I what I'm trying to do. Sorry I'm very new to programming.
  • in which part of the remaining values you want to do the grade? c?D?E?F?G?
  • Choosing Between Class and Struct
  • When I try that I get an error that says I cannot implicitly convert type 'double' to 'string'. on this line --> entry.grade = grade;
  • When I ran my program with you suggestion I got, for the first line "Alexander-->587285-->3.5" Now I just need to total all the columns of grades and then get the average.
  • this only converts the token in the 2 position. I need convert all of the remaining token to doubles, in order to find the average
  • every column from the 3rd on is a grade column.
  • What has this answer got to do with the question?
  • I actually have 33 lines of grades. I just cut it off at 7.
  • @Enigmativity if you read question and comments, you will understand that the author of the question has little programming experience. I am trying to explain him how his code works and how entry.grade = Convert.ToDouble(tokens[2]); gives him correct solution
  • well @MacieMcKensey the while loop in your code loops until the end of your file. why do you have concern about it?
  • what is the use of this? how does he make calculation with this?
  • there is no clarification to this the remain values (grades) from a string to a double. I'm just posting the whole remaining so the he can adjust which columns he wanted to be a grade.