Adding metadata / identifier data to a CSV file?

天涯浪子 提交于 2020-12-01 09:20:16

问题


Is there a way to add a "tag" (add a unique metadata/identifier) to a CSV file without affecting the contents or ability to read/write the file?

I am using Python, but I don't think the language matters here.


回答1:


Just add comment lines that you can parse later.

#Creator:JohnSmith
#Date:....
#Columns:id,username,...
1,JohnSmith
2, ..



回答2:


This would be compliant with W3C embedded metadata format: http://www.w3.org/TR/tabular-data-model/#embedded-metadata

#publisher,W3C
#updated,2015-10-17T00:00:00Z
#name,sensor,temperature
#datatype,string,float
sensor,temperature
s-1,25.5



回答3:


In case you are not sure that all possible readers/writers of the file will be able to interpret (and preserve) comments, create the tag in a second file using some name convention that links them. Example:

myCSVFile.csv
myCSVFile.csv.tag


来源:https://stackoverflow.com/questions/18362864/adding-metadata-identifier-data-to-a-csv-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!