How to store the output data in csv format

ask urgently!!

Jul.04,2022

I don't understand your needs.
the following is for reference only:

file_name = 'output.csv'
with open(file_name, 'w+') as f:
    for key, val in six.iteritems(result):
        f.write('\t{}:{}\n'.format(str(key), str(val)))
< hr > < H1 > updated at 18:38 on 2019.2.22 < / H1 >

paste code first ( cannot be copied and pasted directly, it needs to be modified ):

import pandas as pd

-sharp 
columns = ['photo_name']
-sharpfor key, _ in six.iteritems(result):
for key, _ in [[11,1], [22,2], [33,3]]: -sharp 
    columns.append(str(key))
-sharp 
name_list = ['xx' ,'xxx', 'xxxx']

-sharp DataFrame
df_list = []

for name in name_list: -sharp , ......

    -sharp 
    
    -sharp some_dic = { str(key):str(val) for key, val in six.iteritems(result) }
    some_dic = { str(key):str(val) for key, val in [[11,1], [22,2], [33,3]] } -sharp 
    some_dic['photo_name'] = name
    
    some_df = pd.DataFrame([some_dic]) -sharp :List
    df_list.append(some_df)

-sharp DataFrame
final_df = pd.concat(df_list)

-sharp CSV
final_df.to_csv('some_csv.csv', index=False)

you can replace these two places:

all replace [[11 result 1], [22 code 2], [33 code 3] with six.iteritems (result)

.

Code comments: Dictionary must be placed in List

reference from: https://blog.csdn.net/u013061...

the merge part uses pandas.concat () function:

refer to
https://zhuanlan.zhihu.com/p/...
https://www. .zhihu.com / questio...
https://blog.csdn.net/stevenk...

mainly uses the to_csv () function of the pandas library (much like to_excel () )

refer to
https://codeshelper.com/a/11...
https://pandas.pydata.org/pan...

Menu