Renaming Columns Of A Pandas Dataframe Without Column Names
I'm trying to name the columns of my new dataframe after the dataframe.from_dict operation. Simply using pandas.dataframe.from_dict function: df = pd.DataFrame.from_dict(my_dict,or
Solution 1:
If you want the index as the keys in your dict, you don't need to rename it.
df = pd.DataFrame.from_dict(dicts, orient = 'index') #index is namedf.columns = (['number']) #non-index column is numberdf.index.name = 'name'
Or instead of changing the index name you can make a new column:
df = df.reset_index() #named column becomes index, index becomes ordered sequencedf['name'] = df['index'] #new column with names
del df['index'] #delete old column
Post a Comment for "Renaming Columns Of A Pandas Dataframe Without Column Names"