简体   繁体   English

将 ndarray 转换为 Pandas 数据框

[英]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:我试图将pandas列的唯一值放入新的pandas数据框中:

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.我尝试将 res 转换为列表,但仍然出现相同的错误。 How do I resolve this?我该如何解决?

It is not correct to write pd.Dataframe(res);写pd.Dataframe(res)是不对的;

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

Now, it will work.现在,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM