Snorrlaxxx
Snorrlaxxx

Reputation: 168

Convert ndarray to pandas dataframe

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?

Upvotes: 0

Views: 139

Answers (1)

Onur AKKÖSE
Onur AKKÖSE

Reputation: 102

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.

Upvotes: 1

Related Questions