Excel文件中的空值从CSV(而不仅仅是行) [英] Blank Values in Excel File From CSV (not just rows)

查看:285
本文介绍了Excel文件中的空值从CSV(而不仅仅是行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在Excel中打开包含多个列的CSV文件,其中值只有在数字更改时才会显示。例如,数据可能实际为:90,90,90,90,91。但它只会显示为90 ,,,, 91。我真的很喜欢之间的值填充90年代。有没有反正python可以帮助这个?

I'm currently opening CSV files in Excel with multiple columns, where values will only appear if a number changes. For example, the data may ACTUALLY be: 90,90,90,90,91. But it will only appear as 90,,,,91. I'd really like the values in between to be filled with 90s. Is there anyway python could help with this? I really appreciate your help!

推荐答案

一个简短的解决方案(转换 ['90' '90','90','90','90','''','','','','','91'] ,'91'] ):

a short solution (one liner for transforming ['90','','','','','91'] into ['90','90','90','90','90','91']):

 import csv
 spamReader = csv.reader(open('eggs.csv', 'rb'))
 for row in spamReader:
      a = map(lambda i : reduce(lambda y, z: z != "" and z or y, row[:i]), range(1,len(row)+1))
      print ",".join(a)

这篇关于Excel文件中的空值从CSV(而不仅仅是行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆