[英]Read xlsx file into python without losing information
The goal is to read in an xlsx file into python.目标是将 xlsx 文件读入 python。 All information provided is just to give context to the problem.提供的所有信息只是为问题提供背景信息。
In these examples, the date read in should be 2004/07/01
在这些示例中,读入的日期应为2004/07/01
Here's what librecalc displays这是 librecalc 显示的内容
12/30/99
12/30/99
...
Here's what the actual cell formulas are defined as.这是实际单元格公式的定义。
=Date(2004,7,1)
=Date(2004,7,1)
...
pd.read_excel
)案例 1( pd.read_excel
)Displayed results显示结果
00:00:00
00:00:00
...
values
function returns values
function 返回
array([datetime.time(0, 0), datetime.time(0, 0), datetime.time(0, 0), ...,
datetime.time(0, 0), datetime.time(0, 0), datetime.time(0, 0)],
dtype=object)
pd.read_excel(..., parse_date)
案例 2 ( pd.read_excel(..., parse_date)
Displayed results显示结果
2020-04-14
2020-04-14
...
values
function returns values
function 返回
array(['2020-04-14T00:00:00.000000000', '2020-04-14T00:00:00.000000000',
'2020-04-14T00:00:00.000000000', ...,
'2020-04-14T00:00:00.000000000', '2020-04-14T00:00:00.000000000',
'2020-04-14T00:00:00.000000000'], dtype='datetime64[ns]')
Which is today's date, not 2004/7/1
这是今天的日期,而不是2004/7/1
So the problem seems to beyond a simply reformatting the values.因此,问题似乎超出了简单地重新格式化这些值。 It looks python doesn't have any idea how to parse the dates.看起来 python 不知道如何解析日期。
my dudes, if I run "find and replace" and just find "=Date(" and replace it with "=Date(" then everything works. I have like 40 files I need to do that to but it's manageable. That's insane. Why in the world would this work?我的伙计们,如果我运行“查找并替换”并找到“=Date(”并将其替换为“=Date(”,那么一切正常。我有大约 40 个文件需要这样做,但它是可管理的。这太疯狂了。为什么这会奏效?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.