1

I am new to the python. Here, I have the following csv file which looks like ,

Prediction           per_RFC    per_JAPE

     100             100    97.37
    4600             100    86.15
    2200              80      80
    2900             100     100
    160              100     1.36
    3600             100      0
    2000             100      0 

I have the features column like

feat_cols =[100,  156,  160,  162,  200,  256,  262,  2000,  2200,   2600,  2900,3600,4600]

Here, I am trying to get a csv which looks like

100  156  160  162  200  256  262  2000  2200   2600  2900       3600     4600
100       100                      100    80           100       100       100 

So , I am trying to add the values from the csv in this file

can any one help me with this ?

thanks.

3
  • Can you post what you've tried so far? Commented Dec 25, 2019 at 15:33
  • Yes sure I will add that as well Commented Dec 25, 2019 at 15:34
  • @dcg actually I tried but its a very wrong way so. could u please give a bit of hint or something ? Commented Dec 25, 2019 at 15:48

1 Answer 1

2

To generate a DataFrame containing your expected content, run:

df2 = df.set_index('Prediction').per_RFC.reindex(feat_cols, fill_value='')\
    .reset_index().T

Then, to save it to a CSV file, run:

df2.to_csv('output.csv', header=False, index=False)

If you want the content saved just as you wrote (withot commas and with spaces between columns), you can:

  • generate a text variable: tt = df2.to_string(header=False, index=False),
  • save it to an ouptut file.
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.