Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
How do I handle null values in cluster analysis?

I am into fintech business and I have customer level data like below:

Customer ID day1 day2 day3 day4
1 50 0 NaN 5
2 NaN 10 NaN NaN
3 -100 -100 5 0
4 10 -60 0 100
5 20 NaN -20 NaN

In the above data, the rows represent customer unique ID, columns represent the specific day of the year and the values represent the net of credit and debit on that specific day.

For example, for customer ID = 1 on day1, the credit = 100 and debit = 50 therefore net is 50. Zero means credit = debit on that day.

NaN in my data simply shows that on that specific day, the customer neither did any credit or debit transactions from the app, and this knowledge is important to me. Let NaN be the instance of NO INTERACTION.

Now my question is how do I tell K-Means in scikit-learn python to treat NaN values like No Interaction? I don't want to eliminate NaN values. I also don't want to replace NaN values with mean or median values. NaN values are additional information for me and how do I retain this information?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

import numpy as np
df_no = df.replace(np.nan, 'no', regex=True)
over 4 years ago · Santiago Trujillo Report

0

The k-means and other clustering methods using distance (Euclidean distance) to calculate.

To calculate distance you need numbers and all thing must be quantitative.

Exactly, you must delete those or replace those NaN values with the best representative (median or mean or 0).

How do I decide?

Which customer do you think is closer to customer number 1?

customer 2, 3 or 4?

Customer ID day1 day2 day3 day4
1 50 0 NaN 5
2 50 0 0 5
3 50 0 median 5
4 50 0 mean 5
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!