简体   繁体   English

Python例程缩写句子?

[英]Python routine to abbreviate sentences?

I am working with CSV data from Survey Monkey. 我正在使用Survey Monkey的CSV数据。 The problem is that the column names they use are way too long for most database CSV data import routines. 问题在于,它们使用的列名对于大多数数据库CSV数据导入例程来说太长了。 The column names are, literally, the question you asked on the survey. 从字面上看,列名称是您在调查中提出的问题。 So it can take some time to be able to narrow that down to, say, 64 characters for a database column name. 因此,将数据库列名的范围缩小到64个字符可能需要一些时间。 What would a python routine look like to narrow down a question to a few words and/or characters? python例程将问题缩小到几个单词和/或字符会是什么样? I can't just do something like remove the vowels since that would still be too long in most cases. 我不能做一些删除元音的事情,因为在大多数情况下,这仍然太长了。 Thoughts? 有什么想法吗?

If you just need the headers to be unique and less than 64 (are you using postgres btw?) then just use a hash. 如果您只需要标头是唯一的且小于64(您是否在使用postgres btw?),则只需使用哈希即可。

from hashlib import md5

columns = ['reallylongcolumname1', 'reallylongcolumname2']
out = {}
for c in columns:
    h = md5(c).hexdigest()
    # Use 'h' as your new column header!
    out.update({c : h})

save the dictionary "out" somewhere so you can decrypt this later. 将字典“输出”保存在某处,以便稍后解密。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM