0

i have a csv file like below

mt,ht,mh,hh,mp,hp
17,24,80,100,200,300
24,17,100,80,300,200
0,16,75,95,175,250
16,0,95,75,250,175

when i use read csv, i am able to read it to a dataframe. i changed my program so it will calculate these values and stores it to different variables.

so how can i use those variable to be lika a dataframe(header is not conseidered)

say i have variables giving output like this

a= 16
b= 0
c= 95
d= 75
e= 250 
f= 175

and let these be in the respective order of mt,ht,mh,hh,mp,hp. so instead of reding from csv,how can i use these values???

my present code :

data_to_be_predicted = pd.read_csv('C:\Python34\data\input_data.csv')
prediction = decision_tree.predict(data_to_be_predicted)
print(prediction)

what changes have to be made instead of read_csv to use those values that will be calculated before executing this piece of code

1 Answer 1

1

I think you need DataFrame constructor with list:

a= 16
b= 0
c= 95
d= 75
e= 250 
f= 175
L = [a,b,c,d,e,f]

cols = ['mt','ht','mh','hh','mp','hp']
df = pd.DataFrame([L], columns=cols)
#if need same columns as df
#df = pd.DataFrame([L], columns=df.columns)
print (df)

   mt  ht  mh  hh   mp   hp
0  16   0  95  75  250  175
Sign up to request clarification or add additional context in comments.

Comments

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.