Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I want to merge 2 data frames.

The first data frame looks like:

Date    Value

1968-04-01  38.0

1968-04-02  37.6

1968-04-03  37.7

1968-04-04  36.7

1968-04-05  37.2

1968-04-08  37.0

1968-04-09  37.25

1968-04-10  37.6

The second data frame looks like:

1991-06-21  4.44

1991-06-22  4.39

1991-06-24  4.39

1991-06-25  4.37

1991-06-26  4.41

1991-06-27  4.36

Both data sets go up to the present day.

How do I create a new data frame that starts the data in 1991 since that is where the second data set starts? And has a column for each price.

I tried:

df_all_rows = pd.concat([df1, df2])

but this just puts one set of data below the other one.

I guess currently the data does not go up to the present day. But how can I just create a new data frame with only dates that both series have?

Here is what I have:

import numpy as np

import pandas as pd

import pickle

import quandl

from datetime import datetime

df1=quandl.get("BUNDESBANK/BBK01_WT5511", authtoken="6F92X3NEV8DdrhAc_d5_")

df2=quandl.get("PERTH/SLVR_USD_D", authtoken="6F92X3NEV8DdrhAc_d5_")

df2=df2.dropna()

T1 = pd.merge(df1, df2, on=df1.index, how='inner')

1 Answer

0 votes
by (36.8k points)

First, add a bracket after ==x, second, to filter on a pandas data frame you need to add .loc before the bracket

wine_classes = [wine_data_frame.loc[wine_data_frame['class'] == x] for x in range(3)]

This will give you a list of data frames

If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...