[PYTHON] IQ Bot Custom Logic: Delete the last n rows of the table

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

IQ Bot Custom Logic: Delete the last n rows of the table
IQ Bot Custom Logic Basic Key
IQ Bot Custom Logic: Fixed Value Assignment
IQ Bot Custom Logic Related Processing Summary
IQ Bot Custom Logic: Split Application (Apply to Table, Include Error Control)
IQ Bot Custom Logic (Python): Streamline exclusions in loops
IQ Bot Custom Logic: Correcting common reading habits on dates
IQ Bot Custom Logic (Python): Efficient replacement process in a loop
Explain in detail the magical code for IQ Bot table items
IQ Bot Custom Logic (Python): Efficient replacement process in a loop