Skip to content

Tag: pandas

sorting .csv file using pandas

I am using pandas.DataFrame.sort_values to sort my csv. My csv without sorting looks like . I am trying to sort my csv file by numbers in ATOM_id in ascending order. This is my code snippet df.sort_values([“ATOMS_ID”],axis = 0, ascending = [True],inplace = True). This is what I . I am not really s…

Ordering a stacked histplot based on total counts

I have a dataframe which results from: Then, df_grouped is something like: A B count A_1 B_1 10 A_1 B_2 51 A_1 B_3 25 A_1 B_4 12 A_1 B_5 2 A_2 B_1 19 A_2 B_3 5 A_3 B_5 18 A_3 B_4 33 A_3 B_5 44 A_4 B_1 29 A_5 B_2 32 I have plotted a seaborn.histplot using the following code:

Using lamda to compare two columns

My dataframe is like this: df = pd.DataFrame({‘A’: [1,2,3], ‘B’: [1,4,5]}) If column A has the same value as column B, output 1, else 0. I want to output like this: I figured out df[‘is_equal’] = np.where((df[‘A’] == df[‘B’]), 1, 0) worked fine. But …

Group by from wide form in Pandas

I have a DataFrame like this one: I want to find out the characteristics of the Disloyal and Not Satisfied customers that are between 30 and 40 years old, grouping them by the service they have rated: I suspect I have to use melt but I can’t figure out how to groupby from there. Answer With the followin…

Pandas Add rows for each column

I apologise for the title, I know it isn’t the most helpful. What I’m attempting to do is restructure my data so that each of a given column is given it’s own row with certain values carried over from the previous dataframe. My Data in its current form is something like this: And I want to r…