跳至内容
菜单
此问题已终结
2 回复
5277 查看

I'm still learning with this technology. May I know how to put all values in one column using python and xlsx writer?

Ex.

my_dict = {
'Bob': ['eating', 'watching', 'drinking'], 
'Ann': ['shopping', 'eating', 'drawing'], 
'May': ['riding', 'singing', 'dancing']
}

What I did was putting it in another column temporarily.

col_num = 0
row_num = 7
for key, value in my_dict.items():
    worksheet.write(row_num, col_num, key)
    worksheet.write_column(row_num + 1, col_num, value)
    col_num += 1


May I know how can I achieve this kind of format? Hoping to get your opinions and suggestions. Thank you

NameHobby
Bobeating

watching

drinking
Annshopping

eating

drawing
Mayriding

singing

dancing
形象
丢弃
编写者

Hi @Hemangi Rupareliya

I am not able to reply to your comment below. I appreciate your response.

I tried the string but it only returned the single letter per row only. Do you have examples for strings instead of integer?

编写者 最佳答案

I got it now. This is what I did:


row_num = 7

for key, value in my_dict.items():
col_num = 0
worksheet.write(row_num, col_num, key)
 for i in value:
col_num = 1
worksheet.write(row_num, col_num, i)
row_num += 1
形象
丢弃
最佳答案

Hi Moto Dzae,

You can try following code:

worksheet.write(0, 0, 'Name')

worksheet.write(0, 1, 'Value')

row_num = 1

for key, value in my_dict.items():

    col_num = 0

    worksheet.write(row_num, col_num, key)

    for val in value:

        col_num = 1

        worksheet.write_column(row_num, col_num, val)

        row_num += 1

        

形象
丢弃
相关帖文 回复 查看 活动
1
11月 22
2553
7
1月 24
15183
0
2月 17
3246
0
3月 15
3925
0
3月 15
5120