1

I have a series data in python defined as:

scores_data = (pd.Series([F1[0], auc, ACC[0], FPR[0], FNR[0], TPR[0], TNR[0]])).round(4)

I want to append the text 'Featues' at location 0 to the series data.

I tried scores_data.loc[0] but that replaced the data at location 0.

Thanks for your help.

Joe
  • 357
  • 2
  • 10
  • 32
  • Does this answer your question? [how do I insert a column at a specific column index in pandas?](https://stackoverflow.com/questions/18674064/how-do-i-insert-a-column-at-a-specific-column-index-in-pandas) – C0rn Apr 10 '22 at 16:05
  • 1
    @C0rn this only works for DataFrames – mozway Apr 10 '22 at 16:08

1 Answers1

1

You can't directly insert a value in a Series (like you could in a DataFrame with insert).

You can use concat:

s = pd.Series([1,2,3,4])

s2 = pd.concat([pd.Series([0], index=[-1]), s])

output:

-1    0
 0    1
 1    2
 2    3
 3    4
dtype: int64

Or create a new Series from the values:

pd.Series([0]+s.to_list())

output:

0    0
1    1
2    2
3    3
4    4
dtype: int64
mozway
  • 194,879
  • 13
  • 39
  • 75
  • thanks for your input. I tried to input the text column, but I am still stuck. I converted the text data to a series, but still have issues inserting the text. Using your example, this was my attempt: `s = pd.Series([1,2,3,4]) s2 = pd.Series(['FeatExtr']) pd.Series(s[0]+s2.to_list())` – Joe Apr 10 '22 at 16:40