0

I am trying to just get the unique values of a pandas column into a new pandas dataframe as such:

res = df.resolution.unique()
a = pd.DataFrame()
a['Unique Resolution Types'] = pd.DataFrame(res)

But I am getting this error:

ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series

I tried converting res into a list but still the same error. How do I resolve this?

2
  • 1
    Why not pd.DataFrame(res, columns=['Unique...'])? Commented Nov 6, 2020 at 18:25
  • No problem @Snorrlaxxx ;) Commented Nov 6, 2020 at 18:44

1 Answer 1

1

It is not correct to write pd.Dataframe(res);

res = df.resolution.unique()
a = pd.DataFrame()
a['Unique Resolution Types'] = res

Now, it will work.

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

3 Comments

'a' is already a dataframe. You fill in the 'a' dataframe with res.
a = pd.DataFrame(res, columns=['Unique...']) is correct.
For code block in comments use tilde i.e. ` .Cheers good day mate. ;)

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.