Skip to content

Tag: dataframe

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…

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 …

split the string in dataframe in python

I have a data-frame and one of its columns are a string which separated with dash. I want to get the part before the dash. Could you help me with that? The desire output is: Answer You could use str.replace to remove the – and all characters after it: Output: