Pandas dataframe is not printing

Question:

I have converted my numpy array into pandas dataframe, when I want to rename the column title from "0" to any other name, the dataframe is not printing. Why>?

climate_change_max=data_set["Climate change (kg CO2 eq.)"].max()
climate_change_min=data_set["Climate change (kg CO2 eq.)"].min()

CLIMATE_CHANGE_only_still_normalized=data_frame_of_prediction_still_normalized.drop(["Predicted Climate change, incl biogenic carbon (kg CO2 eq.)","Predicted Fine Particulate Matter Formation (kg PM2.5 eq.)"," Predicted Fossil depletion (kg oil eq.)","Predicted Freshwater Consumption (m^3)","Predicted Freshwater ecotoxicity (kg 1,4-DB eq.)","Predicted Freshwater Eutrophication (kg P eq.)","Predicted Human toxicity, cancer (kg 1,4-DB eq.)","Predicted Human toxicity, non-cancer (kg 1,4-DB eq.)","Predicted Ionizing Radiation (Bq. C-60 eq. to air)","Predicted Land use (Annual crop eq. yr)","Predicted Marine ecotoxicity (kg 1,4-DB eq.)","Predicted Marine Eutrophication (kg N eq.)","Predicted Metal depletion (kg Cu eq.)","Predicted Photochemical Ozone Formation, Ecosystem (kg NOx eq.)","Predicted Photochemical Ozone Formation, Human Health (kg NOx eq.)","Predicted Stratospheric Ozone Depletion (kg CFC-11 eq.)","Predicted Terrestrial Acidification (kg SO2 eq.)","Predicted Terrestrial ecotoxicity (kg 1,4-DB eq.)"], axis=1)
CLIMATE_CHANGE_only_still_normalized

    Predicted Climate change (kg CO2 eq.)
18  0.087270
171 0.471559

fff=CLIMATE_CHANGE_only_still_normalized.to_numpy()
fff
array([[0.08726976],
       [0.47155913],

final_value = (fff*(climate_change_max - climate_change_min) + climate_change_min)
final_value
array([[0.09221854],
       [0.32832593],

data_frame_of_prediction_DE_normalized=pd.DataFrame(final_value,index=CLIMATE_CHANGE_only_still_normalized.index)
data_frame_of_prediction_DE_normalized

       0
18  0.092219
171 0.328326


prediction_DE_normalized = data_frame_of_prediction_DE_normalized.rename(columns={"Unnamed: 0": "Predicted Climate change (De-normalized) (kg CO2 eq.)"}, inplace=True)
print (prediction_DE_normalized)
None
Asked By: JZ0

||

Answers:

Instead of simply using "data_frame_of_prediction_DE_normalized_F"
use print(data_frame_of_prediction_DE_normalized_F).

Answered By: MahendraReddy

The problem here is that you specified inplace="True". When you do that, pandas modifies the array you passed in and returns None.

You need either:

data_frame_of_prediction_DE_normalized.rename(columns={"Unnamed: 0": "Predicted Climate change (De-normalized) (kg CO2 eq.)"}, inplace=True)

without the assignment, or

prediction_DE_normalized = data_frame_of_prediction_DE_normalized.rename(columns={"Unnamed: 0": "Predicted Climate change (De-normalized) (kg CO2 eq.)"})

without the inplace.

Answered By: Tim Roberts
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.