0

I have two dataframes:

A =
date,station_uuid,diesel,e5,e10,dieselchange,e5change,e10change
2019-05-01 00:01:07+02,00061511-4c4d-4444-8888-acdc00000001,1.289,1.469,1.439,0,1,0

and

B = 
uuid,name,brand,street,house_number,post_code,city,latitude,longitude
00060723-0001-4444-8888-acdc00000001,BAGeno Raiffeisen eG,freie tankstelle,Künzelsauer Strasse,7,74653,Ingelfingen ,49.296821594238,9.6613845825195

Where B contains a row for each uuid of A.

I want to add columns of B to A where the uuid has the same value.

So for example I want to add brand and city to A for matching uuids

EDIT: Basically B is a detailed description of uuid of A and i want to merge the two datasets, to have all feature columns of B in A

gustavz
  • 2,964
  • 3
  • 25
  • 47

3 Answers3

1

Use this simple command:

A = pd.merge(A, B['brand','city'], how='left',
                                   left_on='station_uuid', right_on='uuid')
1

Use pd.merge:

a = pd.merge(a, b[['uuid', 'brand', 'city']], how='left',
         left_on='station_uuid', right_on='uuid').drop(labels=['uuid'], axis=1)
Mohit Motwani
  • 4,662
  • 3
  • 17
  • 45
0

merge is a good way to do this, however if you want to keep the index and order of dataframe A, you can use following:

A[['brand', 'city']] = B.set_index(['uuid'])[['brand', 'city']].reindex(A['station_uuid'])

and this only works when there's no duplicated value in the column uuid.

Woods Chen
  • 574
  • 3
  • 13