[英]How to set pandas series index from a dataframe and fill the series with other data?
I have a pandas dataframe myDataFrame
with many columns and a multiple index(es) (two) I want to create a series that has the same indexing as my dataframe myDataFrame
but at each row I set a value.我有一个包含许多列和多个索引(两个)的
myDataFrame
数据myDataFrame
我想创建一个与我的数据myDataFrame
具有相同索引的系列,但在每一行我都设置了一个值。
I was thinking of something along the lines of:我在想一些事情:
mySeries.set_index(myDataFrame.index)
for i in mySeries.index()
mySeries.loc[i] = someValue
Thank you very much!非常感谢!
你可以做
pd.Series(somevalue, index = df.index)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.