Search code examples
pythonpandasdataframe

Convert a dataset into a dataframe with two columns


I have a dataset X which I have tried to convert into a dataframe.

The dataset X is as follows:

 X= woe_transform.fit_transform(df)


   libelle_situation_professionnelle:AUTRES  libelle_situation_professionnelle:RETRAITE  ...  montant_echeance_d:(1347.0, 1561.0]  montant_echeance_d:(1709.0, 15508500.0]
0                                         0                                           0  ...                                False                                    False

[1 rows x 26 columns]

Iam trying to convert it to a dataframe ( i managed to do for one column only).

feature_name = X.columns.values
feature_values=X.iloc[0].values

summary_table = pd.DataFrame(columns=["Feature name"], data=feature_name)
    
print(summary_table)

                                         Feature name
0            libelle_situation_professionnelle:AUTRES
1          libelle_situation_professionnelle:RETRAITE
2           libelle_situation_professionnelle:SALARIE
3   libelle_situation_professionnelle:TRAVAILLEUR ...
4                   solde_trim1_d:(-6691655.0, 436.0]
5                       solde_trim1_d:(436.0, 3895.0]
6                     solde_trim1_d:(3895.0, 33317.0]
7                          duree_dossier_d:(120, 180]
8                          duree_dossier_d:(180, 240]
9                          duree_dossier_d:(240, 400]
10                      montant_nominal_d:(0, 140000]
11                 montant_nominal_d:(170500, 180500]
12                 montant_nominal_d:(180500, 205000]
13                 montant_nominal_d:(205000, 220000]
14                 montant_nominal_d:(220000, 412000]
15         montant_nominal_d:(412000, 10000000000000]
16                         taux_interets_d:(0.0, 4.2]
17                         taux_interets_d:(5.5, 6.4]
18                         taux_interets_d:(6.4, 8.0]
19                          mois_anciennete_d:(6, 12]
20                         mois_anciennete_d:(12, 24]
21                         mois_anciennete_d:(24, 48]
22                        mois_anciennete_d:(48, 500]
23                   montant_echeance_d:(0.0, 1347.0]
24                montant_echeance_d:(1347.0, 1561.0]
25            montant_echeance_d:(1709.0, 15508500.0]

I am looking to do it for both columns feature_values and feature_name in order to have a dataframe with two columns as opposed to one.

I have tried this code but it failed.

summary_table = pd.DataFrame(columns=["Feature name", 'Feature Values'], data=[feature_name, features_values])

Can someone help please?


Solution

  • The 'data' parameter expects a list of rows or a dictionary, not a list of columns.

    Try :

    symmary_table = pd.DataFrame({
         "Feature name": X.columns.values,
         "Feature Values": X.iloc[0].values
    })