[英]how to make 1 by n dataframe from series in pandas?
I have a huge dataframe, and I index it like so:我有一个巨大的数据框,我像这样索引它:
df.ix[<integer>]
Depending on the index, sometimes this will have only one row of values.根据索引,有时这将只有一行值。 Pandas automatically converts this to a Series, which, quite frankly, is annoying because I can't operate on it the same way I can a df.
Pandas 会自动将其转换为系列,坦率地说,这很烦人,因为我无法像 df 那样对其进行操作。
How do I either:我该如何:
1) Stop pandas from converting and keep it as a dataframe ? 1)阻止熊猫转换并将其保留为数据框?
OR或者
2) easily convert the resulting series back to a dataframe ? 2)轻松将结果系列转换回数据帧?
pd.DataFrame(df.ix[<integer>])
does not work because it doesn't keep the original columns. pd.DataFrame(df.ix[<integer>])
不起作用,因为它不保留原始列。 It treats the <integer>
as the column, and the columns as indices.它将
<integer>
视为列,将列视为索引。 Much appreciated.非常感激。
您可以执行df.ix[[n]]
以获得第n
行的单行数据帧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.