Reputation: 761
features_df = (pd.concat(feature_weight_list)
.pivot(index='n', columns='features', values='values'))
print(features_df)
features_df.to_csv (r'C:/Users/USER12/Downloads/AB.csv', index = False, header=True)
I am saving this file at its pattern is like that
feature 1 , feature 2 , feature 3
Then I am taking transpose but the feature column name is not appearing in rows
this is the code I am using. can anyone help
features_df_T = features_df.T
print(features_df_T)
features_df_T.to_csv (r'C:/Users/USER12/Downloads/transposeAB.csv', index = False, header=True)
Upvotes: 0
Views: 63
Reputation: 209
Setting the index
to False
in the DataFrame.to_csv
method will remove the indexing, which has become the column names after the transposition of the dataframe. Try removing index=False
when saving the dataframe to a csv file.
features_df_T.to_csv(r'C:/Users/USER12/Downloads/transposeAB.csv')
Upvotes: 1