将2D numpy数组转换为数据框行 [英] Converting a 2D numpy array to dataframe rows
本文介绍了将2D numpy数组转换为数据框行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表列表,我想将其作为一行.我最近得到的就是使用此帖子.但是,我找不到答案.
I have a list of list that I would like to make it as a row. The closest I got was using this post. However, I could not get my answer.
例如,假设我有一个testarray
值,
For example lets say I have a testarray
of values,
([[ 26.85406494],
[ 27.85406494],
[ 28.85406494],
[ 29.85406494],
[ 30.85406494],
[ 31.85406494],
[ 32.85406494],
[ 33.85406494],
[ 34.85406494],
[ 35.85406494],
[ 36.85406494],
[ 37.85406494],
[ 38.85406494],
[ 39.85406494],
[ 40.85406494],
[ 41.85406494]])
我需要像这样的pandas
DataFrame行,
I need like as a pandas
DataFrame row like this,
Row_value
0 26.85406494
1 27.85406494
2 29.85406494
...
我尝试了以下方法,
df = pd.DataFrame({'Row_value':testarray})
我得到一个错误,
ValueError:如果使用所有标量值,则必须传递索引
ValueError: If using all scalar values, you must pass an index
如何通过索引传递这些值?
How can I pass those values with an index?
推荐答案
仅将DataFrame构造函数与参数列一起使用:
Use DataFrame constructor only with parameter columns:
df = pd.DataFrame(a, columns=['a'])
print (df)
a
0 26.854065
1 27.854065
2 28.854065
3 29.854065
4 30.854065
5 31.854065
6 32.854065
7 33.854065
8 34.854065
9 35.854065
10 36.854065
11 37.854065
12 38.854065
13 39.854065
14 40.854065
15 41.854065
这篇关于将2D numpy数组转换为数据框行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文