Excel 和 CSV 之间的区别是什么?

huangapple go评论227阅读模式
英文:

What is the difference between Excel and CSV?

问题

我正在学习Python。现在我正在尝试使用pandas库将数据存储到.csv文件中。

我知道csv是逗号分隔值,数据是由**逗号(,)**分隔的。我的疑问是,由于Excel和csv文件都将数据存储在工作表中,它们之间有什么区别?

英文:

I am learning about Python. Now I am trying to store the data to .csv file using pandas library.

I know csv is comma separated values, the data is separated by comma(,). My doubt is since both excel and csv files store data in a sheet, what is the difference between them?

答案1

得分: 2

Excel XLSX和CSV文件格式之间的主要区别在于文件大小和格式。

在*.CSV文件中,文件大小较小,数据如下所示:
(没有格式,只有原始数据)

而且,如果你使用文本编辑器打开,你会得到这个:

idx,col1,col2
123,aaa,xxx
456,bbb,yyy
789,ccc,zzz

而在*.XLSX文件中,文件大小较大,数据如下所示:
(这种格式允许表格、边框、背景颜色、粗体等格式化)

而且如果你用文本编辑器打开,你会得到这个:

PK ! A7傁n [Content_Types].xml ?(?
琓蒼?絎?D綱墶嚜??[$?榵扻$跺(鼄'fQU??Ql蟍&?&YB@鉲.鶼O$璻?鼿烢偆琕嵆悑5? 镲拥 L岗b.j""%5?3缌騈锽珗?C%?妾?陕YK)ub8x僐-J轜技Q23V$瘺sU.旝?盤勾?I晔?燷県:C@i?╩23???g€/#莺矢2 泌x|隚簼惝秛_?傃悓U燨詹w筳鋸髾s箪4去瓑-蔤e霳?e|鮫,ん佅??愸y絼s?i? 藓??s??耵V7?麛幵88彍? 梬a懏:??霤rh伥??轁鄸??  PK ! 礥0#? L _rels/.rels ?(?

一般情况下,我使用CSV格式来存储原始数据,并使用XLSX格式来展示数据。

英文:

The major differences between Excel XLSX and CSV file format are the file size and the formatting.

In a *.CSV file, the file size is smaller, and the data looks like this:
(there is no formatting, just raw data)
Excel 和 CSV 之间的区别是什么?

And if you open using a text editor, you'd get this:

idx,col1,col2
123,aaa,xxx
456,bbb,yyy
789,ccc,zzz

And in a *.XLSX file, the file size is larger, and the data looks like this:
(this format allows formatting such as tables, borders, background color, bold, etc)
Excel 和 CSV 之间的区别是什么?

And if you open with a text editor, you'd get this:

PK     ! A7傁n     [Content_Types].xml ?(?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 琓蒼?絎?D綱墶嚜??[$?榵扻$跺(鼄'fQU??Ql蟍&?&YB@鉲.鶼O$`璻?鼿烢偆琕嵆悑5?
镲拥 L岗b.j""%5?3缌騈锽珗?C%?妾?陕YK)ub8x僐-J轜技Q23V$瘺sU.旝?盤勾?I晔?燷県:C@i?╩23???g€/#莺矢2
泌x|`隚簼惝秛_?傃悓U燨詹w筳鋸髾s箪4去瓑-蔤e霳?e|鮫,ん佅??愸y絼s?i? 藓??s??耵V7?麛幵88彍? 梬a懏:??霤rh伥??轁鄸??   PK     ! 礥0#?   L   _rels/.rels ?(?     
<truncated>

Generally, I use CSV format to store raw data, and use XLSX format to present the data.

答案2

得分: 1

我的疑惑是Excel和CSV文件都存储在工作表中。

它们并不都存储在工作表中。CSV文件中没有工作表。这是一个常见的误解,因为在Windows中双击CSV文件时会使用Excel打开。Excel将CSV文件中的文本放入工作表中,但该工作表是由Excel创建的,它并不存在于CSV文件中,即使您保存它也是如此。

以下是一些可以看出差异的方法:

如果尝试添加第二个工作表并保存为CSV,它会显示不支持。

如果右键单击编辑CSV文件,而不是双击它,它会在记事本中打开。

如果给工作表命名,比如"Test",然后保存并关闭文件,然后再次打开它,工作表名称不会被保存。Excel将使用文件名作为工作表名称。

如果关闭文件,将其重命名为"Test.csv"之类的名称,然后在Excel中打开文件,工作表名称将变为"Test"。

英文:

> My doubt is both excel and csv file stores data in sheet.

They do not both store data in a sheet. There is no sheet in a csv file.

This is a common misunderstanding because windows uses Excel to open csv files when you double click. Excel puts the text from the csv file into a sheet, but that sheet is created by Excel, it doesn't exist in the csv file, even when you save it.

Here are some ways you can see the difference:

If you try to add a second sheet and save as csv, it will say not supported.

If you right-click > edit the csv file instead of double-click, it will open in notepad.

If you give the sheet a name like "Test", then save and close the file, then open it again, the sheet name will not be saved. Excel will use the filename as the sheet name.

If you close the file, and rename it to something like "Test.csv", then open the file in Excel, the sheet name will now say "Test".

huangapple
  • 本文由 发表于 2023年7月20日 11:55:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726572.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定