0

I want to create a DataFrame with separate columns for PY and ST, however the DataFrame is created with index values of PY.

import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt 

K = 8000 

ST = np.linspace(7000,9000,num=50)  

PO = 50 

PY = np.maximum(ST-K-PO,0)

pd.DataFrame(PY,ST)

Is there a way to create the DataFrame with default index starting from 0 and 2 columns of PY and ST.

1
  • Your index values are ST not PY. Commented Jan 15, 2022 at 4:25

1 Answer 1

1

You can use df = pd.DataFrame(list(zip(PY,ST)),columns=["py","st"])

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Appreciate your help. Is there a reason why first column is taken index ?
Yeah index is the second argument to pandas.DataFrame. pandas.pydata.org/docs/reference/api/pandas.DataFrame.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.