1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] List Literal vs List Multiplication storage and speed comparison

Discussão em 'Python' iniciado por Stack, Setembro 18, 2025.

  1. Stack

    Stack Membro Participativo

    For the input of a pytest function I have a dataframe that has 6 rows and 40 columns for example. The dataframe is made up of None values only. What would be the more appropriate way of creating this dataframe.

    import pandas as pd

    pd.DataFrame([
    [None]*40,
    [None]*40,
    [None]*40,
    [None]*40,
    [None]*40,
    [None]*40,
    ]), columns = input_schema)


    Or in the format below

    pd.DataFrame([
    [None, None, None, None, None, . . ., None],
    [None, None, None, None, None, . . ., None],
    [None, None, None, None, None, . . ., None],
    [None, None, None, None, None, . . ., None],
    [None, None, None, None, None, . . ., None],
    [None, None, None, None, None, . . ., None],
    ]), columns = input_schema)


    Memory and Speed wise it has negligible effect at this scale for me. However, what would be the more appropriate style for writing code. Would list comprehension be a more clearer option then at this point if speed and memory have no significant effect, or something else entirely.

    Continue reading...

Compartilhe esta Página