[Solved] How to find profit or loss percentage from consecutive rows [closed]

df = pd.DataFrame() df[‘Date’] = [‘2017-05-20’, ‘2017-05-20’, ‘2017-05-20’] df[‘Price’] = [50, 60, 45] df[‘Prof/Loss’] = (df[‘Price’] / df[‘Price’].shift())*100 – 100 First, I think your math for calculating the Loss/Profit was wrong, I hope I fixed that for you. Second, you can use the .shift() method to get the previous row, use .shift(-1) to get the … Read more

[Solved] How to calculate percentage of matching values on two arraylists?

Try this: List<String> actual = new ArrayList<>(); List<String> required = new ArrayList<>(); List<String> common = new ArrayList<>(actual); common.retainAll(required); System.out.println(” 100.0 * common / actual = ” + (actual.size() == 0 ? 0 : 100.0 * common.size() / actual.size())); System.out.println(” 100.0 * common / required = ” + (required.size() == 0 ? 0 : 100.0 * … Read more