empty list from columns conditional

Berny

I get the columns from a data frame, what I'm trying to do is, if columns is not empty do this... if is empty then do that... but I'm receiving the error: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() by using the following code:

    sw_col = df_sw.columns
    if sw_col.notnull():
        miss = (sw_col) - (df.columns)
        print(miss)
    else:
        df_sw = pd.concat([df, df_sw], ignore_index=True)

I would appreciate your help guys :)

Nima S

About the error you got, that's because sw_col.notnull() returns an array of boolean values and python cannot decide which element it should consider to execute if or else.

==========================================

(1) When you say columns is empty, do you mean dataframe is empty? Because, columns return the NAMES of columns. if that is the case, then you can use df.empty to check that.

(2) If that's not the case and you are trying to see if the columns have names or not, I think your approach doesn't help since df.columns return the RangeIndex type object when there are no names for columns. So, you can then use isinstance(sw_col, pd.RangeIndex) to see if there are names for the columns of dataframe or not. If it returns True, it means the columns have no pre-defined names.

(3) If you are trying to search for empty columns in a dataframe (columns with no elements), then you can apply df.notnull() and it will return True for each element if it exist in the dataframe. So, then to find the columns that are COMPLETELY EMPTY without even a single element, you can just use a.any() on each column.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Remove empty list from list of list in Scheme

From Dev

Remove empty entries from list

From Dev

Conditional formatting using list from another sheet

From Dev

subtract list of lists from list of lists with conditional arguments

From Dev

Python: pop from empty list

From Dev

How to remove an empty list from a list (Java)

From Dev

deleting empty values from list inside list

From Dev

PostgreSQL: Conditional INSERT INTO on some of multiple columns from difference tables

From Dev

Calculating conditional probability from list

From Dev

create new columns from a list of columns in pandas

From Dev

Pop from empty list

From Dev

How to use the null-conditional operator on an empty list?

From Dev

Pandas - Conditional Calculation Based on Shift Values from Two Other Columns

From Dev

Pandas: replace list of values from list of columns

From Dev

Create column with some values from another columns - Conditional

From Dev

pySpark adding columns from a list

From Dev

Created extra columns from list

From Dev

Empty list conditional

From Dev

Create column with some values from another columns - Conditional

From Dev

Create a XML File from a list based on a conditional

From Dev

Querying empty(undefined) rows/columns from Parse

From Dev

removing empty header columns from a data matrix

From Dev

Concatenate OR conditional expressions from list to "|"

From Dev

Remove empty columns from a DataTable

From Dev

Conditional appending items from a list into multiple documents

From Dev

Appending a value from a list to an empty list in python

From Dev

Conditional format to color cell if matched from a list

From Dev

Python: pop from empty list?

From Dev

Conditional Formatting 1 column based on 5 columns from multiple sheets

Related Related

  1. 1

    Remove empty list from list of list in Scheme

  2. 2

    Remove empty entries from list

  3. 3

    Conditional formatting using list from another sheet

  4. 4

    subtract list of lists from list of lists with conditional arguments

  5. 5

    Python: pop from empty list

  6. 6

    How to remove an empty list from a list (Java)

  7. 7

    deleting empty values from list inside list

  8. 8

    PostgreSQL: Conditional INSERT INTO on some of multiple columns from difference tables

  9. 9

    Calculating conditional probability from list

  10. 10

    create new columns from a list of columns in pandas

  11. 11

    Pop from empty list

  12. 12

    How to use the null-conditional operator on an empty list?

  13. 13

    Pandas - Conditional Calculation Based on Shift Values from Two Other Columns

  14. 14

    Pandas: replace list of values from list of columns

  15. 15

    Create column with some values from another columns - Conditional

  16. 16

    pySpark adding columns from a list

  17. 17

    Created extra columns from list

  18. 18

    Empty list conditional

  19. 19

    Create column with some values from another columns - Conditional

  20. 20

    Create a XML File from a list based on a conditional

  21. 21

    Querying empty(undefined) rows/columns from Parse

  22. 22

    removing empty header columns from a data matrix

  23. 23

    Concatenate OR conditional expressions from list to "|"

  24. 24

    Remove empty columns from a DataTable

  25. 25

    Conditional appending items from a list into multiple documents

  26. 26

    Appending a value from a list to an empty list in python

  27. 27

    Conditional format to color cell if matched from a list

  28. 28

    Python: pop from empty list?

  29. 29

    Conditional Formatting 1 column based on 5 columns from multiple sheets

HotTag

Archive