QST: Why have my data values been replaced by “NaN” after using qcut?
- [ ] I have searched the [[pandas] cut, qcut](https://stackoverflow.com/questions/tagged/pandas) on StackOverflow for similar questions.

- [ https://stackoverflow.com/questions/63929143/why-have-my-data-values-been-replaced-by-nan-after-using-qcut] I have asked my usage related question on [StackOverflow](https://stackoverflow.com).

---

#### Question about pandas

**Note**: If you'd still like to submit a question, please read [this guide](
https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports) detailing how to provide the necessary information for us to reproduce your question.


I am working with pandas dataframe of 9000 rows and 6 columns. At this point, I am trying to convert the continuous variable 'Experience' years of a job into the categorical variable 'Level' of expertise (beginner - intermediate - advanced - expert) for each of the 4 jobs (Commercial Manager - Business Developer - Web Marketer - Traffic Manager).

Giving that years experience range are not the same for each job, I utilised "qcut" to divide data into 4 groups as follows:

(You can run the code below to get the dataframe sample)
```python
import pandas as pd


df = pd.DataFrame({'Job': ['Commercial Manager', 'Traffic Manager', 'Web Marketer', 'Commercial Manager', 'Commercial Manager', 'Web Marketer', 'Commercial Manager', 'Commercial Manager', 'Traffic Manager', 'Business Developer', 'Business Developer', 'Web Marketer', 'Traffic Manager', 'Traffic Manager', 'Commercial Manager', 'Business Developer', 'Traffic Manager', 'Commercial Manager', 'Business Developer', 'Business Developer', 'Web Marketer'], 
                   'Experience': [1.00000, 3.00000, 3.00000, 1.50000, 2.00000, 6.00000, 0.00000, 4.00000, 8.00000, 5.00000, 0.50000, 3.00000, 3.00000, 0.00000, 2.00000, 3.00000, 0.50000, 3.00000, 3.00000, 8.00000, 3.50000]})


levels = ["beginner", "intermediate", "advanced", "expert"]
jobs = ["Commercial Manager", "Business Developer", "Web Marketer", "Traffic Manager"]


def convert(levels, jobs):
  for j in jobs:
    df["Level"] = pd.qcut(df.loc[df["Job"] == j, "Experience"].rank(method="first"), q = 4, labels = levels, duplicates = "drop")
  return df

convert(levels, jobs)

```

It appears that it only worked for "Traffic Manager" and it replaced the other 'level' experience with NaN. I am really lost. Any help please?