I want to save a certain amount of money into savings account at the rate of 5% for 10 years. I need $10000.00 at the end of the 10 years.
Task is to know the capital or the initial investment
futureValue=(10000)
interestRate=(0.05)
depositePeriod=(10)
capital=futureValue/(1+interestRate)*depositePeriod
print(capital)
I get 95238.xxxxx. but i expect something like 952.00
because capital should not be more interest at the end of the period
this is more of a math problem then a code, but here, this FOR loop would give you the answer you're looking for
futureValue=(10000)
interestRate=(0.05)
depositePeriod=(10)
capital = futureValue
for no_of_years in range(depositePeriod):
capital = capital/(1+interestRate)
print(capital)
Related
original data frame:
Date
Detail
31/03/22
I watch Netflix at home with my family 4 hours
01/04/22
I walk to the market for 3km and I spent 11.54 dollar
02/04/22
my dog bite me, I go to hospital, spend 29.99 dollar
03/04/22
I bought a game on steam 7 games spen 19.23 dollar
result data frame:
Date
Detail
Cost
31/03/22
I watch Netflix at home with my family 4 hours
0
01/04/22
I walk to the market for 3km and I spent 11.54 dollar
11.54
02/04/22
my dog bite me, I go to hospital, spend 29.99 dollar
29.99
03/04/22
I bought a game on steam 7 games spen 19.23 dollar
19.23
Describe my question:
If Detail Column does not contain specific string which is begin with sp.. and end with dollar
then value in Cost col equal zero.
If Detail Column does contain specific string which is begin with sp.. and end with dollar,
then value in Cost col equal value in the middle of specific string which is begin with sp..
and end with dollar.
I try to use regex but it's got first int that contain in the col like
| 01/04/22 | I walk to the market for 3km and I spent 11.54 dollar| 3 |
You should be able to use a regex pattern of a form such as:
df['Cost'] = df['Detail'].str.extract(r'sp\D*([\d\.]*)\D*dollar')
This will look for the literal string sp and then any non-digit characters after it. The capture group (denoted by the ()) looks for any digits or period characters, representing the dollar amount. This is what is returned to the Cost column. The final part of the pattern allows any number of non-digit characters after the dollar amount, followed by the literal string dollar.
The pd.NA for rows which don't have a cost can then be replaced with 0:
df['Cost'] = df['Cost'].replace({pd.NA: 0})
If you want to make any enhancements I used this site to test the regex: https://regexr.com/6ir6o
If I have an average YOY growth of say 2.5%, current year sales of $500,000, and target sales of $1,000,000. Is there a way to calculate the number of years until I hit my target (assuming a continued YOY growth rate of 2.5%), without calculating each additional years's sales on a different row?
You can use the NPER function for this:
=NPER(Growth,0,currentSales,-targetSales)
Note that this gives the same result as #Dominique, but is using a built-in Excel function.
Also, by virtue of the nature of Excel financial functions, the signs for the current and future Sales need to be different.
There's a simple formula for this:
Money_end = (1+r/100)^Y*Money_begin
Where:
Money_begin = the starting amount of money, in this case 500000.
Money_end = the finishing amount of money, in this case 1000000.
r = the percent ratio, in this case 2.5.
Y = the amount of years, which you are looking for.
So, your question comes down to solving this equation:
1000000 = (1+2.5/100)^Y * 500000
2 = 1.025^Y
Y = log(2)/log(1.025)
If you want this to be solved by Excel, you might use the formula and use the Solver basic Excel feature for coming up with the same (but numerical instead of analytical) result.
I have a homework assignment in which I have to calculate the minimum amount of coins required for an inputted monetary value.
I've been trying to wrap my head round the logic involved, but I can't quite grasp it. I copied most of it from this website, so if you could explain it to me, I'd be very grateful!
First I tried loads of if, else statements and I knew I had to use % (modulus). But it didn't really work.
n1=float(input("Enter a monetary amount: "))
n1=n1*100
pound=0
fiftyp=0
twentyp=0
tenp=0
onep=0
pound=n1/100
n1%=100
fiftyp=n1/50
n1%=50
twentyp=n1/20
n1%=20
tenp=n1/10
n1%=10
onep=n1
print(int(pound), int(fiftyp), int(twentyp), int(tenp), int(onep))
This code, however, doesn't work, probably due to rounding issues? For example, when inputted 2.30, it outputted 2 0 1 0 9, i.e. 2pounds twenty pence and nine pence, when it should be 2 0 1 1 0, i.e. 2pounds twenty pence, ten pence.
Again, if you could also help me understand how the bulk of the above code works, I'd be very grateful. Thank you in advance!
I have a report which is downloaded from a Warehouse Management System.
On this report there is a time column which unfortunately puts the time into a string of numbers that can be anywhere from 5-8 digits long.
I.e.
22434900 = 22:43:49:00 with 22 being the hour, 43 the minutes, 49 the seconds.
2480000 = 02:48:00:00 with 2 being the hour, 48 the minutes etc.
54300 = 00:05:43:00
The 00 on the end (milliseconds) doe not change in each number so is quite irrelevant.
Is there an easy way to format the text in these cells so it shows as a time as oppose to a number?
Thanks in advance.
I know I'm late, but here's an alternate solution:
=TIMEVALUE(TEXT(A1/100,"00\:00\:00.00"))
Again, as mentioned in Jerry's answer, you'll need to use cell formatting of hh:mm:ss.00
You can use TIME with some math functions:
=TIME(INT(A1/1000000),MOD(INT(A1/10000),100),MOD(A1/100,100))
TIME takes 3 parameters: hours, minutes and seconds.
To get the hours, I'm dividing by 1000000, then INT rounds it down to the closest integer.
To get the minutes, I'm first dividing by 10000, but there is still the hours in that result. So I use MOD (which gives the remainder when a number is divided by another number). In the first example, the division gives 2243, and the remainder when dividing this by 100 is 43, which is the number of minutes I'm looking for.
To get the seconds, I divide the number by 100 and similar to the minutes, I use MOD to remove the minutes and hours parts. I am not using INT here in case there are milliseconds, which will be kept using this formula.
Also note that I am using the formatting hh:mm:ss.00, because excel complains if I try using hh:mm:ss:00.
For your Warehouse Management System query you may want to try something like this:
• Taking the 6 digit numeric time and making this into a string that the time function can handle
• Using the digits function to avoid issues with varying lengths of data (i.e. 64512 vs 1113012)
• Use the function Time over this string to return the value (this way we can add hours or minutes as the example below)
Here is an example to experiment with this and :
select MyTimeField
, time(int(MyTimeField/10000) || ':' ||
substring(digits(MyTimeField),3,2) || ':' ||
substring(digits(MyTimeField),5,2))
from MyTable where MyCompany = 1 and MyInvoiceDate = Current_date
I have a list of cost figures with start dates and end dates which I need to split between months, I have searched for the solution to this problem but cannot seem to find one that will work with partial months i.e.( startdate:01/01/2015 enddate: 15/04/2015 cost:10000) which would leave figures like Jan:2857, Feb:2857, Mar:2857, Apr:1429.
I have been trying to modify this example: http://www.excel-university.com/excel-formula-to-allocate-an-amount-into-monthly-columns/ but having no luck getting the partial months working.
Any suggestions or help would be most welcome. Thanks in Advance
if you calculate it on daily basis, would it be ok? the result would be:
01.01.2015 01.02.2015 01.03.2015 15.04.2015
2.857,14 2.857,14 2.857,14 1.428,57
your daily amount is:
=10.000/(DAYS360(startdate;enddate;TRUE)+1)
(be carefull of true and false argument)
under the dates or instead of 2.857,14 etc. insert the formula:
=IF(DAY("your date")>1;DAY("your date");30) * daily amount
This formula assumes that you want to have 30 days in each month:
=IF(DAY(01.01.2015)>1;DAY(01.01.2015);30)
result = 30
=IF(DAY(15.04.2015)>1;DAY(15.04.2015);30)
result = 15
so if months begins with a date different from the 1st it will give you the number of days.
if you want to match months with your startdate and enddate (if i understood your comment correctly), you could do:
=IF(OR(
AND(MONTH(startdate)=MONTH(your date);YEAR(startdate)=YEAR(your date));
AND(MONTH(enddate)=MONTH(your date);YEAR(enddate)=YEAR(your date))
);"match";"no match")
by this you make sure that month and year correspond.
If you want to get the number of days in a month automatically, you could use:
=DAY(DATE(YEAR("your date");MONTH("your date")+1;1)-1)
but this does not assume anymore 30 days, you can change it with if statement
I hope this helps,
Best - AB