Skip to content
Advertisement

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 sure why my .csv is not get sorted

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 I want to use lambda here because I used a similar line in another case before.

Extracting Rows and Appending Them to the End of Other Rows

I have a dataframe containing a transaction list. What I want to do is create something like a P&L per transaction and additionally make it suitable for entry into another software. Basically, I would like to get a “Buy” transaction and find the next row with a “Sell” transaction. Then take that “Sell” transaction and append it to the end

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:

Advertisement