I've been running some groupings on a dataframe that I have and saving the results in variables. However, I just noticed that the variables are actually being saved as series rather than dataframes.
I've seen tutorials/docs on how to convert a series to a dataframe, but all of them show only static data (by manually typing each of the values into an array), and this isn't an option for me, because I have over 2 million rows in my data frame.
So if I have
TopCustomers = raw_data.groupby(raw_data['Company'])['Total Records'].sum()
Top10Customers = TopCustomers.sort_values().tail(10)
How can I turn Top10Customers into a dataframe? I need it because not all plots work with series.
The syntax frame = { 'Col 1': series1, 'Col 2': series2 } doesn't work because I only have 1 series
pd.DataFrame(TopCustomers.sort_values().tail(10))Top10Customers.to_frame()?Top10CustomersDF = pandas.DataFrame({'Customers':Top10Customers.index, 'Total Records':Top10Customers.values})and it got alignedcompaniesis currently the index. If so, what you want isTop10Customers.reset_index().