python3 修改版
def sizes(s):
return "{:.6f} KB".format(int(s) / 1024.0) , \
"{:.6f} MB".format(int(s) / 1024.0 ** 2), \
"{:.6f} GB".format(int(s) / 1024.0 ** 3)
df_test['size_kb'], df_test['size_mb'], df_test['size_gb'] = zip(*df_test['size'].apply(sizes))
df_test
df_test['size'].apply(sizes) 返回的内容
array([('971.614258 KB', '0.948842 MB', '0.000927 GB'),
('106776.084961 KB', '104.273520 MB', '0.101830 GB')], dtype=object)
#list(df_test['size'].apply(sizes))
[('971.614258 KB', '0.948842 MB', '0.000927 GB'),
('106776.084961 KB', '104.273520 MB', '0.101830 GB')]
zip(*a) 将a 当做list 解
s=[['A1','A2','A3'],
['B1','B2','B3']]
a,b,c=zip(*s)
print(a,b,c)
('A1', 'B1') ('A2', 'B2') ('A3', 'B3')
网友评论