Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Pandas merge question
#1
I hope you are all having a good day. I want to know why my merge below is returning the key error that is stated below my code. Any help would be appreciated.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

dict1={'eggs':(1,7,44,76,23,56,22,21,20,11,12,81),'month':('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec')}

dict2={'bread':(22,43,17,9,22,16,71,82,24,34,54,45),'months':('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec')}

df1=pd.DataFrame(dict1)

df2=pd.DataFrame(dict2)

df1.columns.values[1]='months'

pd.merge(left=df1,right=df2,on='months')
KeyError: 'months'
Quote
#2
Your example works for me. Perhaps you forgot to run line 15 (that renames month column as months column), so there was no 'months' key in df1 and merge failed?
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Counting Criteria in Pandas Question Koenig 1 144 Sep-30-2019, 05:16 AM
Last Post: perfringo
  Function question using Pandas smw10c 7 2,758 Feb-12-2019, 06:52 PM
Last Post: Nathandsn
  Simple pandas dataframe question popohoma 1 596 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  Why can't I merge pandas dataframes learnpython2018 2 1,061 Sep-23-2018, 05:53 PM
Last Post: learnpython2018
  question on pandas datareader kit12_31 3 4,265 Feb-05-2018, 11:55 PM
Last Post: snippsat
  Newbie question on how to use pandas.rolling_mean zydjohn 5 7,915 Dec-09-2017, 08:42 PM
Last Post: j.crater
  Pandas question takaa 3 1,308 Dec-05-2017, 01:03 PM
Last Post: takaa

Forum Jump:


Users browsing this thread: 1 Guest(s)