Understanding Bandas Series Line-Direction Coupling

Asked 2 years ago, Updated 2 years ago, 35 views

I would like to use the code below to combine date,p into the header, but it doesn't work.
How can I do it?

Also, the tick contains the date information, and we make the year and year information with str(t.year)+str(t.month).p assumes the score from machine learning, which in itself is a single number.

Results

date20154.000000
f 0.666667
date20155.000000
f 0.666667
dtype:float64

It appears as shown in .
The shape I want is ↓.

datef
201540.666667
201550.666667

a=pd.Series(int(str(t.year)+str(t.month))),f1),index=['date','f'])
 b=pd.Series(int(str(t.year)+str(t.month+1),f1),index=['date','f'])

 pd.concat([a,b],axis=0)

python pandas

2022-09-29 21:21

2 Answers

What do you think of this?

pd.DataFrame([a,b])

If the results are high, create an empty DataFrame with only the column name defined first and

df=pd.DataFrame (columns=['date','f'])

You can do it by appending.

df=df.append(a,ignore_index=True)

You can also append directly to the dictionary without creating a series.

df=df.append({'date':int(str(t.year)+str(t.month))), 'f':f1}, ignore_index=True)


2022-09-29 21:21

I think pd.concat([a,b],axis=1).T can also do it


2022-09-29 21:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.