Answers for "form a dataframe in python"

0

python function to scale selected features in a dataframe pandas

# make a copy of dataframe
scaled_features = df.copy()

col_names = ['co_1', 'col_2', 'col_3', 'col_4']
features = scaled_features[col_names]

# Use scaler of choice; here Standard scaler is used
scaler = StandardScaler().fit(features.values)
features = scaler.transform(features.values)

scaled_features[col_names] = features
Posted by: Guest on May-15-2020
4

python loop through column in dataframe

# Iterate over two given columns only from the dataframe
for column in empDfObj[['Name', 'City']]:
   # Select column contents by column name using [] operator
   columnSeriesObj = empDfObj[column]
   print('Colunm Name : ', column)
   print('Column Contents : ', columnSeriesObj.values)
Posted by: Guest on March-04-2020

Code answers related to "form a dataframe in python"

Python Answers by Framework

Browse Popular Code Answers by Language