Home > database >  Problem with Converting matplotlib plot into a PD Dataframe?
Problem with Converting matplotlib plot into a PD Dataframe?

Time:05-26

Thanks in advance. I am facing a problem in pandas dataframe. I want to turn off the indexing and rename the column name...But it is not working. I attached a screenshot and code in here... Thank you again

from google.colab import files
import pandas as pd

plot_train_acc = [neighbors,training_acc1];
plot_test_acc = [neighbors,testing_acc1];

#Save into Array

Man_train_acc = pd.DataFrame(plot_train_acc[:], index=None) # train acc. for Manhattan
Man_test_acc = pd.DataFrame(plot_test_acc[:],index=None) # test acc. for Manhattan

#Transpose into vertical 

Man_train_acc_Transpose = Man_train_acc.T;
Man_test_acc_Transpose = Man_test_acc.T;


Man_train_acc_Transpose_new = Man_train_acc_Transpose.rename(columns={'0': 'Col_1', '1': 'Col_2'})

print(Man_train_acc_Transpose_new)

enter image description here

CodePudding user response:

There are integers 0, 1, not strings '0', '1', so for rename use:

Man_train_acc_Transpose_new = Man_train_acc_Transpose.rename(columns={0:'Col_1', 1:'Col_2'})

Or:

Man_train_acc_Transpose_new = Man_train_acc_Transpose.set_axis(['Col_1','Col_2'], axis=1)

Pandas DataFrame and Series have always index values, so is possible only hidden them:

print (Man_train_acc_Transpose_new.to_string(index=False))

Or omit them if write to file:

Man_train_acc_Transpose_new.to_csv('file.csv', index=False)
  • Related