Joe
Joe

Reputation: 395

How to add text element to series data in Python

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.

Upvotes: 1

Views: 425

Answers (1)

mozway
mozway

Reputation: 261850

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

Upvotes: 1

Related Questions