0

i need actual_new column from actual in pandas dataframe.

start time      end time        actual      actual_new
4/1/2022 20:00  4/1/2022 21:00  0.749123    0.749123
4/1/2022 21:00  4/1/2022 22:00  0.749123    0.770175
4/1/2022 22:00  4/1/2022 23:00  0.749123    0.725439
4/1/2022 23:00  4/2/2022 0:00   0.749123    0.659649
4/2/2022 0:00   4/2/2022 1:00   0.749123    0.245614
4/2/2022 1:00   4/2/2022 2:00   0.749123    0.078947
4/1/2022 21:00  4/1/2022 22:00  0.770175    0.749123
4/1/2022 22:00  4/1/2022 23:00  0.770175    0.770175
4/1/2022 23:00  4/2/2022 0:00   0.770175    0.725439
4/2/2022 0:00   4/2/2022 1:00   0.770175    0.659649
4/2/2022 1:00   4/2/2022 2:00   0.770175    0.245614
4/2/2022 2:00   4/2/2022 3:00   0.770175    0.078947
4/1/2022 22:00  4/1/2022 23:00  0.725439    0.749123
4/1/2022 23:00  4/2/2022 0:00   0.725439    0.770175
4/2/2022 0:00   4/2/2022 1:00   0.725439    0.725439
4/2/2022 1:00   4/2/2022 2:00   0.725439    0.659649
4/2/2022 2:00   4/2/2022 3:00   0.725439    0.245614
4/2/2022 3:00   4/2/2022 4:00   0.725439    0.078947
4/1/2022 23:00  4/2/2022 0:00   0.659649    0.749123
4/2/2022 0:00   4/2/2022 1:00   0.659649    0.770175
4/2/2022 1:00   4/2/2022 2:00   0.659649    0.725439
4/2/2022 2:00   4/2/2022 3:00   0.659649    0.659649
4/2/2022 3:00   4/2/2022 4:00   0.659649    0.245614
4/2/2022 4:00   4/2/2022 5:00   0.659649    0.078947
4/2/2022 0:00   4/2/2022 1:00   0.245614    0.749123
4/2/2022 1:00   4/2/2022 2:00   0.245614    0.770175
4/2/2022 2:00   4/2/2022 3:00   0.245614    0.725439
4/2/2022 3:00   4/2/2022 4:00   0.245614    0.659649
4/2/2022 4:00   4/2/2022 5:00   0.245614    0.245614
4/2/2022 5:00   4/2/2022 6:00   0.245614    0.078947
4/2/2022 1:00   4/2/2022 2:00   0.078947    0.749123
4/2/2022 2:00   4/2/2022 3:00   0.078947    0.770175
4/2/2022 3:00   4/2/2022 4:00   0.078947    0.725439
4/2/2022 4:00   4/2/2022 5:00   0.078947    0.659649
4/2/2022 5:00   4/2/2022 6:00   0.078947    0.245614
4/2/2022 6:00   4/2/2022 7:00   0.078947    0.078947
2
  • Can you clarify how the two columns are related? E.g. how does 0.749123 in actual become 0.078947 in actual_new? Commented Nov 8, 2022 at 15:36
  • This data is after exploding the dataframe.In actual columns 6 unique values repeated 6 times but in new columns i want set of 6 unique values repeat rows wise on the interval of 6. Thanks for your help! Commented Nov 8, 2022 at 15:41

2 Answers 2

1
df['actual_new'] = list(df['actual'].unique())*int(df.shape[0]/len(uniques))
Sign up to request clarification or add additional context in comments.

Comments

0

Try this way:

df['actual_new'] = df['actual']

or

df['actual_new'] = df.apply(lambda x: x['actual'], axis = 1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.