0

I want to fill an empty dataframe using a list.

Here is the empty dataframe.

old_dates= pd.date_range((today -dt.timedelta(days=2)), (today-dt.timedelta(days=1))).strftime("%d %b")
columns=old_dates
df_verif=pd.DataFrame(columns=columns)
df_verif


24 Jun  25 Jun

All of the column names are dates (and will be longer through time). I then want to fill only the first row with one value for each day. Let's say I have a list that contains two values. How would I then add those values, in the order that they appear in the list, under the corresponding date?

test=[2.5,2.5]

Expected output:

0   24 Jun  25 Jun
1   2.5     2.5

2 Answers 2

2

If I'm not mistaken, it should be:

df_verif.loc[0] = test

This adds the elements of test to the row at index 0 in the order in which they are in test.

Sign up to request clarification or add additional context in comments.

Comments

0

if you want to add test = [2.5, 2.5] at the end of DataFrame (without explicitly set the row number):

df_verif = df_verif.append({k:v for k,v in zip(columns,test)},  ignore_index=True )

df_verif

Out[1]:

    24 Jun  25 Jun
0   2.5     2.5

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.