columnsorting

Sorting a dataset by month with month column as an object

Sorting a dataset by month with month column as an object Question: I’m trying to sort my data by "Month" (which is an object and I can’t convert it to datetime for some reason), but nothing happens when using .sort_values. No error is printed either. I have three months in my current dataset, "Jul", "Aug", …

Total answers: 1

Moving a specific column of a dataframe to first column

Moving a specific column of a dataframe to first column Question: I have a dataframe as follows: s = df.head().to_dict() print(s) {‘BoP transfers’: {1998: 12.346282212735618, 1999: 19.06438060024298, 2000: 18.24888031473687, 2001: 24.860019912667006, 2002: 32.38242225822908}, ‘Current balance’: {1998: -6.7953, 1999: -2.9895, 2000: -3.9694, 2001: 1.1716, 2002: 5.7433}, ‘Domestic demand’: {1998: 106.8610389799729, 1999: 104.70302507466538, 2000: 104.59254229534136, 2001: 103.83532232336977, …

Total answers: 3

Multiple column sorting in multiindex dataframe

Multiple column sorting in multiindex dataframe Question: I have the following dataframe: dic = {‘US’:{‘Traffic’:{‘new’:1415, ‘repeat’:670}, ‘Sales’:{‘new’:67068, ‘repeat’:105677}}, ‘UK’: {‘Traffic’:{‘new’:230, ‘repeat’:156}, ‘Sales’:{‘new’:4568, ‘repeat’:10738}}} d1 = defaultdict(dict) for k, v in dic.items(): for k1, v1 in v.items(): for k2, v2 in v1.items(): d1[(k, k2)].update({k1: v2}) df = pd.DataFrame(d1) df.insert(loc=0, column=(”, ‘Mode’), value=[0,5]) df.insert(loc=1, column=(”, ‘Symbol’), value=[2,1]) …

Total answers: 1

Extracting a column out

Extracting a column out Question: I have a list of array of the form. params = [[array([7.30946927, 2.40445369])], [array([7.30886254, 2.40241312])], [array([7.21275251, 2.09358208])], [array([7.61757898, 0.15745312])], [array([7.76890152, 2.70100186])], [array([7.82943027, 2.39066977])], [array([7.20117715, 2.05259557])], [array([7.21455828, 2.09081677])], [array([7.46129784, 1.9455824 ])]] I want to extract out the first element (7.3, 7.3 etc) into a new array that I want to use …

Total answers: 1

Create dataframe with specific slices out of existing dataframe, based on date variabels

Create dataframe with specific slices out of existing dataframe, based on date variabels Question: I have the following dataframe (df) with a column ‘date’ and ‘values’. I am looking for a solution how to create a new dataframe from the variables start_MM_DD and end_MM_DD (month and day). For each year a column with the corresponding …

Total answers: 2

Reordering Pandas Columns based on Column name

Reordering Pandas Columns based on Column name Question: I have columns with similar names but numeric suffixes that represent different occurrences of each column. For example, I have columns (company_1, job_title_1, location_1, company_2, job_title_2, location_2). I would like to order these columns grouped together by the prefix (before the underscore) and then sequentially by the …

Total answers: 2