As I understand it, when I'm changing a column name, the decision to set inplace to true or false depends on whether I want to mutate the original dataframe (inplace=True
) or create a new dataframe object (inplace=False
).
I have a source file in xlsx where the column names I want for my dataframe are in row 2. I need to change one of the column names so it conforms with the rest of the analysis.
df_original = pd.read_excel('filepath.xlsx', sheet_name = "LookUpReferences", skiprows = 1)
df_original = df_original.rename(columns = {'WrongName': 'CorrectName'}, inplace = True)
When I do this and, for example, look at output via the head()
function, I get
AttributeError: 'NoneType' object has no attribute 'head'
I can resolve this by creating a new dataframe and setting inplace=False
, i.e.
df_new = df_original.rename(columns = {'WrongName': 'CorrectName'}, inplace = False)
But this will get cumbersome. So I'm trying to understand why the inplace=True
isn't working the way I want it to. Is it the skiprows portion of the read_excel() ??? That's the only reason I can think of why I'm getting a NoneType. But, very much like Jon Snow, I know nothing...
Thanks!