Cannot reset_index inplace on a Series to create a DataFrame

Viewed 4234

When I am trying to reset the index of my dataFrame, it is not working.

new = pd.DataFrame(columns=['a','b','Amount1'])
new['Amount1'] = [0,1,6,7,8,9]
new['a'] = ['sarim',1,2,3,4,'sarim']


df_tf = new[new['a']=='sarim']['Amount1']
df_tf.reset_index(inplace=True)

ret_df['Amount1'] = df_tf
2 Answers

you can try,

df_tf.reset_index(drop = True, inplace=True)
ret_df['Amount1'] = df_tf

or

ret_df['Amount1'] = list(df_tf)

You could reset index on df then convert to series

new.loc[new["a"] == 'sarim'].reset_index(drop=True)["Amount1"]
Related