2

I have this kind of dataframe, I want to split it into two dataframe if the "FT" column is empty

df

    HomeTeam    AwayTeam         FT
0   Colo Colo   U. De Concepcion    
1   Cobresal    U. Espanola 
2   Deportes    S. Wanderers    
3   La Serena   A. Italiano      A
4   O'Higgins   Colo Colo        D
5   Palestino   Coquimbo         D

Tried this code but df still the same

if "" in df['FT']:
    df1 = df[df['FT'] == '']
    df = df[df['FT'].notna("")]

1 Answer 1

3

It looks like the column is not missing (na) but has as value '' (empty string). In that case you can do:

df_missing = df.loc[df['FT'] == "", :]
df_not_missing = df.loc[df['FT'] != "", :]

The .loc allows you to select rows for which the values match some criteria, columns for which the values match some criteria or both. The first indexer is for selecting rows, the second (optional) for selecting columns.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.