python - Pandas can't join DataFrames after set_index with exception `IndexError: index 2 is out of bounds for axis 0 with size 2` -


when run code below join operation throws indexerror: index 2 out of bounds axis 0 size 2. if change index's name before write file works, in context i'm trying use file writing operation hard change.

to fair, pandas version bit old: 0.12.0. can't find evidence pandas bug has been fixed, wrong.

import os import pandas pd  filepath = os.path.expanduser("~/desktop/foo.csv")  def write_df(filepath):     # http://pandas.pydata.org/pandas-docs/version/0.16.2/dsintro.html#from-dict-of-series-or-dicts     d = {'one' : pd.series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd']),          'two' : pd.series([5., 6., 7., 8.], index=['a', 'b', 'c', 'd'])}     df = pd.dataframe(d)     #df.index.name = "letter" # fixes     df.to_csv(filepath)  def read_df(filepath):     df = pd.read_csv(filepath)     # inplace = false not here     df.rename(columns={'unnamed: 0': 'letter'}, inplace=true)     df.set_index("letter", inplace=true)     return df  write_df(filepath) dfs = [read_df(filepath), read_df(filepath)] dfs[0].join(dfs[1], lsuffix="_0", rsuffix="_1") 

whatever issue fixed in pandas 0.16.2. h/t unutbu


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -