Good day.
I have series of data in cvs file like below,
1,,,
1,137.1,1198,1.6
2,159,300,0.4
3,176,253,0.3
4,197,231,0.3
5,198,525,0.7
6,199,326,0.4
7,215,183,0.2
8,217.1,178,0.2
9,244.2,416,0.5
10,245.1,316,0.4
I want to extract specific data from second column for example 217.1 and 245.1 and have them concatenated into a new file like,
8,217.1,178,0.2
10,245.1,316,0.4
I use cvs module to read my cvs file, but, I can''t extract specific data as I desire. Could anyone kindly please help me. Thank you.
解决方案Just open the cvs file, and open a second cvs file to write.
Then loop through the first cvs file, (for line in fileobject), and check whether the data in the second column matches your criteria. If it does, write the line to the second cvs file.
Personally, if your data is really as simple as you suggest, I wouldn''t bother with the cvs file, and just use the built in open, read, write and close commands. Should only be a handful of lines. If you''re struggling, post back with what you''ve tried, and I''ll write out an example of the code. I''m rushing now, though, I''m afraid.
+1 on opening it as a normal file and splitting on the comma. Also, check the length of each split record before doing anything else. You should not rely on their not being any empty or malformed records in the file.
@Glenton
Dear Glenton,
Actually I''m dealing with 10K rows of data in my csv file. I will try your suggestion. Thanks for prompt replied.