Issue
I'm trying to grab user input from a function and put it into a dataframe using Jupyter Notebook and pandas. This is the closest thing I've gotten so far. I'm trying to do a number generator from a math equation and retaining those results in a variable. Then having those results in that variable put into a dataframe and displayed in rows with columns. It has to be called from a function. Maybe I could save results into a csv then call on that? Any help would be greatly appreciated!
def main():
global df
n = eval(input("How many numbers should I print? "))
print("This program illustrates a chaotic function.")
x = eval(input("Enter the first number between 0 and 1: "))
y = eval(input("Enter the second number between 0 and 1: "))
for i in range(n):
x = 3.9 * x * ( 1 - x)
y = 3.9 * y * ( 1 - y)
df = pd.DataFrame(columns = {"1st Number": [x], "2nd Number": [y]})
print(df + (x,y))
Solution
you can use this one, it works good :
def main():
global df
n = int(input("How many numbers should I print? "))
print("This program illustrates a chaotic function.")
x = float(input("Enter the first number between 0 and 1: "))
y = float(input("Enter the second number between 0 and 1: "))
X = []
Y = []
for i in range(n):
x = 3.9 * x * ( 1 - x)
X.append(x)
y = 3.9 * y * ( 1 - y)
Y.append(y)
df = pd.DataFrame(list(zip(X, Y)),
columns =['1st Number', '2nd Number'])
print(df + (x,y))
Answered By - Khadija
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.