1

I have a data frame as below :

 member_id  |   loan_amnt   |  Age   | Marital_status
 AK219      |    49539.09   |  34    |  Married 
 AK314      |    1022454.00 |  37    |  NA
 BN204      |    75422.00   |  34    |  Single

I want to create an output file in the below format

 Columns       | Null Values | Duplicate |
 member_id     |  N          |   N       |
 loan_amnt     |  N          |   N       |
 Age           |  N          |   Y       |
 Marital Status|  Y          |   N       |

I know about one python package called PandasProfiling but I want build this in the above manner so that I can enhance my code with respect to the data sets.

2
  • Did you try something? Commented May 2, 2019 at 5:49
  • @Ruturaj- I ran python package PandasProfiling ,it gave me the details about Null values , duplicate values, Maximum , min values. But I want to build this by my own. I need to enhance this further. Commented May 2, 2019 at 6:12

3 Answers 3

2

Use something like:

m=df.apply(lambda x: x.duplicated())
n=df.isna()
df_new=(pd.concat([pd.Series(n.any(),name='Null_Values'),pd.Series(m.any(),name='Duplicates')],axis=1)
                     .replace({True:'Y',False:'N'}))
Sign up to request clarification or add additional context in comments.

Comments

0

Here is python one-liner:

pd.concat([df.isnull().any() , df.apply(lambda x: x.count() != x.nunique())], 1).replace({True: "Y", False: "N"})

Comments

0

Actually the Pandas_Profiling gives you multiple options where you can figure out if there are repetitive values.

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.