Linked Questions
27 questions linked to/from Sorting columns in pandas dataframe based on column name
21
votes
1
answer
8k
views
Pandas Pivot Table manually sort columns [duplicate]
For a given data frame:
UUT testa testb testc testd
DateTime
2017-11-21 18:47:29 1.0 1.0 1.0 3.0
2017-11-21 18:47:30 1.0 2.0 1....
1
vote
1
answer
123
views
Order of nested dictionaries or order of pandas columns for exporting in Excel [duplicate]
I would like to export certain data contained in nested dictionaries to a PD dataframe and then to Excel:
counter=0
for m in [3]:
for column, wind_speed in enumerate(wind_speeds):
for row,ti in ...
1681
votes
43
answers
2.7m
views
How to change the order of DataFrame columns?
I have the following DataFrame (df):
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.rand(10, 5))
I add more column(s) by assignment:
df['mean'] = df.mean(1)
How can I move the ...
479
votes
7
answers
584k
views
How to add pandas data to an existing csv file?
I want to know if it is possible to use the pandas to_csv() function to add a dataframe to an existing csv file. The csv file has the same structure as the loaded data.
18
votes
3
answers
50k
views
Assign line colors in pandas
I am trying to plot some data in pandas and the inbuilt plot function conveniently plots one line per column. What I want to do is to manually assign each line a color based on a classification I make....
9
votes
4
answers
11k
views
is there a magic method for sorted() in Python?
I understand that there are magic methods in python that can be overwritten by classes to control the way certain built in functions treat the members of these classes. For example, the behavior of ...
2
votes
3
answers
1k
views
rearranging columns after getting dummies
A B C D E
0 165349.20 136897.80 471784.10 New York 192261.83
1 162597.70 151377.59 443898.53 California 191792.06
2 ...
4
votes
3
answers
685
views
Python Pandas: Sorting Columns
I'm trying to sort the columns of a .csv file. These are the names and the order of the columns:
'Unnamed: 0', 'Unnamed: 1',
'25Mg BLK', '25Mg 1', '25Mg 2',
'44Ca BLK', '44Ca 1', '44Ca 2',
'137Ba ...
2
votes
3
answers
874
views
Reorder row values csv pandas
I have a csv file
1 , name , 1012B-Amazon , 2044C-Flipcart , Bosh27-Walmart
2 , name , Kelvi20-Flipcart, LG-Walmart
3, name , Kenstar-Walmart, Sony-Amazon , Kenstar-Flipcart
4, name , LG18-...
1
vote
2
answers
545
views
Reordering Pandas Columns based on Column name
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, ...
0
votes
2
answers
1k
views
Matching dataframe row order with another dataframe in Python based on str data
I have 2 dataframes that both contain the same columns but are ordered differently. The first dataframe is ordered this way:
Code Description Value
0 01 A .3
1 01 B ...
2
votes
1
answer
784
views
Reorder Dataframe columns contains string and number in ascending order
I tried reordering the column using sort_index, but it doesn't behave as I had hoped.
After sorting, it reorders as below:
>>> list(df)
['blocks_written_1',
'blocks_written_10',
'...
0
votes
0
answers
850
views
Pasting from dataframe to Excel columns with a loop
I want to copy the columns from an Excel file in a certain order, and then paste the columns I concatenated to the data frame df1 into another excel file at a certain interval.
In other words, in ...
-1
votes
1
answer
642
views
Polars: Pivoting by Int64 column not keeping numeric order
I have a column called VERSION_INDEX which is Int64 and is a proxy for keeping a list of semantic software versions ordered such that 0.2.0 comes after 0.13.0. When I pivot, the column names created ...
0
votes
1
answer
388
views
How to arange columns of test dataframe in same sequence as that of the train dataframe
I have following train dataframe kind of dataframe,
train_df
A B C D
6 8 7 3
7 9 1 8
11 7 2 3
and my test dataframe columns arrangement is as following,
test_df
C A D B
...