Reading CSV File

I have a excel spreadsheet filled with multiple columns of data and I am supposed to use this data to do some key performance indicators. So far I have managed to read in the data and store it in a .txt file for later use but I am unsure whether I should store this data in separate .txt files or store them in strings. I do have to use the data eventually so I am unsure which approach would be better.
This is what the data looks like
1
2
3
4
5
 AppCategory	Rating	Reviews	Size	Installs	Type	Price	Content Rating	Genres	Last Updated	Current Ver	Android Ver
Photo Editor & Candy Camera & Grid & ScrapBook	ART_AND_DESIGN	4.1	159	19M	10,000+	Free	0	Everyone	Art & Design	7-Jan-18	1.0.0	4.0.3 and up
Coloring book moana	ART_AND_DESIGN	3.9	967	14M	500,000+	Free	0	Everyone	Art & Design;Pretend Play	15-Jan-18	2.0.0	4.0.3 and up
U Launcher Lite – FREE Live Cool Themes, Hide Apps	ART_AND_DESIGN	4.7	87510	8.7M	5,000,000+	Free	0	Everyone	Art & Design	1-Aug-18	1.2.4	4.0.3 and up
Last edited on
depends on what you are doing exactly.
is this school, or work? Excel can probably do whatever you are trying to do, its highly programmable.
If you must drop out to process it outside, text is easy to read and you can convert it later. If you try to read it as a specific type into c++ from the start, you will have trouble if there is every a typo or intentional cell with data of another type in it. If you are sure the data is error free, then reading into types is fine.
Thanks for the reply, this is my school project so I must use C++ to do any data analysis needed. I know my next step is to sort the data but I am unsure how I should sort it. I see different approaches that I can use. I can either read all the data and write it to a text file which I have done so far, but I am rethinking if I should store them in arrays immediately instead of writing to a file and use an array for each column. Eg: App[], Category[].....

EDIT: The dataset most likely might have missing data. I am given a dataset and must clean the data and use it to do analysis.

Thanks for any assistance provided
Last edited on
Hello nicholasjb1996,

I Think there may be some misunderstanding here. If what you show in the code tags is the file you are calling a CSV file then it is not. If you have a different file that you are using then post a sample of it.

You say:
So far I have managed to read in the data and store it in a .txt file for later use
Why do you need to do this?

You should be reading the CSV file and storing the fields in variables or a struct. I would lean towards the struct and store it in a vector or array for later use.

Without seeing the proper CSV file and what code you have written it is mostly a guess.

You can use "std::getline" something like: std::getline(inFile, part, ',');. If what you read happens to be a numerical value then you would need to follow the "getline" with numericalVariable = std::stoi(part); This is for an "int" use "std::stod" for a double.

I am not sure if you are aware that Excel can save a file as a CSV file to start with. Then all you have to do is read the file.

Sorry if I seem to be rambling, but I am not quit sure exactly what you have done and are trying to do.

I have an Excel spread sheet that saves it-self as a CSV file and a C++ program that transforms the data into a ".html" file that I use about every other day. So what you need to do would not be that difficult.

Hope that helps. If there is anything else I can do let me know.

Andy
Hello Andy, thanks for replying. The file is a CSV file but the data in each cell is a lot so when I copy and paste it, it looks like that of the above.

Why do you need to do this?

I only did that at the beginning when I was creating my program to ensure I can read the CSV file and all the data in it. Then I was unsure about how I should store the data i.e. if it would be easier to store it in a txt file and then read the data from there into variables or just read them into arrays. The CSV file has 10841 rows and 13 columns of data. I have not covered structs yet but I will look it up later. Do I have to use a struct or can I just store it in arrays? I appreciate the help, I have attached a link to the CSV file and a snippet of the code I am using to read the file.

https://drive.google.com/open?id=16alAP3gSxqoWpzbDNQ6mcCT48JNpTjVa

1
2
std::ifstream ifile("googleplaystore.csv");
std::ofstream ofile("appdata.txt");


1
2
3
4
5
6
7
8
9
void KPI::readfile(std::ifstream &object, std::ofstream &oobject)
{
	while (object.good())
	{
		std::getline(object, data);
		oobject << data << std::endl;
		std::cout << data << std::endl;
	}
}


Last edited on
Topic archived. No new replies allowed.