python分析csv文件一节值 不同的个数_如何使用python从csv文件解析特定的数字数据...

1586010002-jmsa.png

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值