Search code examples
pythonvaex

Initialize Vaex Dataframe Column to a value


I want to initialize a column of my vaex dataframe to the int value 0

I have the following:

right_csv = "animal_data.csv"

vaex_df = vaex.open(right_csv,dtype='object',convert=True)

vaex_df["initial_color"] = 0

But this will throw an error for line 3 complaining about how vaex was expecting a str Expression and got an integer instead.
How do I make a vaex expression set every row of a column to a single value?


Solution

  • Good question, the most memory efficient way now (vaex-core v2.0.2, vaex v3) is:

    df['test'] = vaex.vrange(0, len(df))  # add a 'virtual range' column, which takes no memory
    df['test'] = df['test']* 0 + 111  # multiply by zero, and add the initial value
    

    We should probably have a more convenient way to do this, I opened https://github.com/vaexio/vaex/issues/802 for this.