0

After i exported data from dataframe to googlesheet, it looked like this:

Screenshot from googlesheet

I wish i can merge repeated columns and get this kind of result:

enter image description here

This is the part of code which is responsible for merging cells:

df1 = wks.get_as_df()

df1 = df1.apply(pd.to_numeric, errors='ignore')

df2 = pd.pivot_table(df1[df1.SSPU == 'K01'],index=['SSPU','Color'], 
columns = ["Size"],values=['USFBA',"近30天销量(US)",'US 
Turnover'],fill_value=0, aggfunc=sum)
gc=
pygsheets.authorize(service_file='/Users/dongan/PycharmProjects
/PyProjects/AntonGS.json')

sh = gc.open('BU2_EOL库存处理PY')

wks1 = sh[2]

wks1.set_dataframe(df2,(3,3),copy_index=True)

wks1.merge_cells(start='E3', end='J3', merge_type='MERGE_ALL', sheet=[2])

But it doesn't work. It returns an error:

AttributeError: 'Worksheet' object has no attribute 'merge_cells'

(according to pygsheets reference it should have it)

Antonych
  • 79
  • 7

2 Answers2

0

In the pygsheets merge_cells is given under DataRange. so first get the range you want to merge as a Datarange. you can use

rng = wks.get_values('A1', 'A5',returnas='range')
rng.merge_cells()

PS. code not tested, so watch-out for minor syntax errors.

Nithin
  • 5,470
  • 37
  • 44
0

Check the version of your pygsheet module. The function merge_cells() was introduced in version 2.0.4 (both for DataRange and Worksheet classes).

Hayden Eastwood
  • 928
  • 2
  • 10
  • 20