function - Python Pandas - Segmentation Fault after renaming columns? -


so after create dataframe in pandas, have function capitalizes headers. when try access dataframe information after capitalizing, segmentation fault error. if try access before applying function, don't have problems. doing wrong?

reader = pd.read_csv(infile)  def capitalize_headers(df):     in range(len(list(df.columns.values))):         df.columns.values[i] = (df.columns.values[i]).upper()  capitalize_headers(reader)  print reader['columnname'] 

if uppercase of column names accessing column has lowercase characters throw error.

specifically, line

df.columns.values[i] = (df.columns.values[i]).upper() 

converts 'columnname' 'columnname'. column access in pandas case sensitive, access column df['columnname'].

also, here more efficient/pythonic way of doing using pandas str methods.

df.columns = df.columns.str.capitalize() 

Comments