I want to use IQ Bot to delete the "last n rows" of a table, what should I do? I received a question from a colleague.
I'm not sure how many other similar use cases there are, but I'll post a memorandum instead.
Delete the last n lines
#Code that must be entered when operating the table (first)
import pandas as pd
df = pd.DataFrame(table_values)
#From here onward is this process
n = 2 #Specify the number of n that you want to delete the last n lines.
for i in range(len(df)-n,len(df)):
df.at[str(i),"Column name"] = "Delete this line" # 「Column name」はテーブルに存在する適当なColumn name
df = df[df["Column name"] != "Delete this line"] # 「Column name」は↑と揃える
#Code that must be entered when operating the table (last)
table_values = df.to_dict()
Recommended Posts