File size: 631 Bytes
e84d35a
 
 
 
 
 
 
 
8a677e1
e84d35a
 
 
 
 
 
 
 
8a677e1
 
e84d35a
 
 
 
8a677e1
e84d35a
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Trim df."""
import pandas as pd


# fmt: off
def trim_df(
        df1: pd.DataFrame,
        len_: int = 4,
        ignore_index: bool = True,
) -> pd.DataFrame:
    # fmt: on
    """Trim df."""
    if len(df1) > 2 * len_:
        df_trimmed = pd.concat(
            [
                df1.iloc[:len_, :],
                pd.DataFrame(
                    # [["...", "...",]],
                    [["..."] * len(df1.columns)],
                    columns=df1.columns,
                ),
                df1.iloc[-len_:, :],
            ],
            ignore_index=ignore_index,
        )
        return df_trimmed
    return df1