1

i have two dataframe like df1

    time    kw
0   13:00   30
1   13:02   28
2   13:04   29

and df2

  time    kw
1   13:01   30
2   13:03   28
3   13:05   29

i want to add rows from one dataframe to another for end result like

  time    kw
1   13:00   30
2   13:01   30
3   13:02   28
4   13:03   28
5   13:04   29
6   13:05   29

Please help.. I concat both dataframeresult_df = pd.concat([df1, df2]), but it just put them side by side. Secondly i tried to append both dataframe, but still not what i am looking for Thanks in advance

2
  • Please do add your efforts in your question which is highly encouraged on SO. Thank you Commented Apr 10, 2021 at 14:36
  • Thank u, i just did Commented Apr 10, 2021 at 14:44

2 Answers 2

3
import pandas as pd

df1 = pd.DataFrame([("13:00", 30), ("13:02", 28), ("13:04", 29)], columns=["time", "kw"])
df2 = pd.DataFrame([("13:01", 30), ("13:03", 28), ("13:05", 29)], columns=["time", "kw"])

df = pd.concat([df1, df2]).sort_values("time")
Sign up to request clarification or add additional context in comments.

Comments

1

Use df.append with df.sort_values:

In [2362]: df1.append(df2).sort_values('time')
Out[2362]: 
    time  kw
0  13:00  30
1  13:01  30
1  13:02  28
2  13:03  28
2  13:04  29
3  13:05  29

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.