File size: 585 Bytes
d5ff673
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ca37ad
 
d5ff673
 
 
 
 
 
 
 
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
"""Trim df."""
import pandas as pd


# fmt: off
def trim_df(
        df1: pd.DataFrame,
        len_: int = 4,
) -> 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=1,
        )
        return df_trimmed
    return df1