使用 pandas 在 google 电子表格中追加现有行的新行
Append new row in google spreadsheet with existing rows using pandas
我正在尝试在 googlespreadsheet 中追加新行,因为我在下面的脚本中使用过
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from gspread_dataframe import get_as_dataframe, set_with_dataframe
import pandas as pd
ws = gc.open("test_submit").worksheet("Oct-2019")
d = {'Name': ['T', 'Z'], 'ID': [3, 4]}
df = pd.DataFrame(data=d)
existing = get_as_dataframe(ws)
existing = existing.dropna(how='all')
updated = existing.append(df)
set_with_dataframe(ws, updated)
但它会在空白列 header 中创建不必要的列,名称为 unnamed0、unnamed1 ....unnamed。此外,它不会以现有列名的正确格式附加行。感谢任何帮助
我已经使用以下脚本解决了我的问题
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from gspread_dataframe import get_as_dataframe, set_with_dataframe
import pandas as pd
ws = gc.open("test_submit").worksheet("Oct-2019")
d = {'Name': ['T', 'Z'], 'ID': [3, 4]}
df = pd.DataFrame(data=d)
existing = get_as_dataframe(ws)
existing = existing.dropna(how='all')
new_df= pd.DataFrame()
new_df = new_df.append(existing)
new_df = new_df.append(df)
set_with_dataframe(ws, new_df,row=1, col=1, include_index=False, include_column_header=True,
resize=False, allow_formulas=True)
我正在尝试在 googlespreadsheet 中追加新行,因为我在下面的脚本中使用过
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from gspread_dataframe import get_as_dataframe, set_with_dataframe
import pandas as pd
ws = gc.open("test_submit").worksheet("Oct-2019")
d = {'Name': ['T', 'Z'], 'ID': [3, 4]}
df = pd.DataFrame(data=d)
existing = get_as_dataframe(ws)
existing = existing.dropna(how='all')
updated = existing.append(df)
set_with_dataframe(ws, updated)
但它会在空白列 header 中创建不必要的列,名称为 unnamed0、unnamed1 ....unnamed。此外,它不会以现有列名的正确格式附加行。感谢任何帮助
我已经使用以下脚本解决了我的问题
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from gspread_dataframe import get_as_dataframe, set_with_dataframe
import pandas as pd
ws = gc.open("test_submit").worksheet("Oct-2019")
d = {'Name': ['T', 'Z'], 'ID': [3, 4]}
df = pd.DataFrame(data=d)
existing = get_as_dataframe(ws)
existing = existing.dropna(how='all')
new_df= pd.DataFrame()
new_df = new_df.append(existing)
new_df = new_df.append(df)
set_with_dataframe(ws, new_df,row=1, col=1, include_index=False, include_column_header=True,
resize=False, allow_formulas=True)