In this dataframe, how to go about appending a column named "class_name", with a text string, that is based on another column.
| x | y | z | not used | Label |
|---|---|---|---|---|
| -3.8481877 | -0.47685334 | 0.63422906 | 1.0396314 | 1 |
| -2.320888 | 0.65347993 | 1.1519914 | 0.12997247 | 1 |
| 1.5827686 | 1.4119303 | -1.7410104 | -4.6962333 | 2 |
| -0.1337152 | 0.13315737 | -1.6648949 | -1.4205348 | 2 |
| -0.4028037 | 1.332986 | 1.3618442 | 0.3292255 | 1 |
| -0.015517877 | 1.346349 | 1.4083523 | 0.87017965 | 0 |
| -0.2669228 | 0.5478992 | -0.06730786 | -1.5959451 | 0 |
| -0.03318152 | 0.3263167 | -2.116833 | -5.4616213 | 1 |
There are the values the new column will take based on the values in the 'Label' column:
0 == 'avocados'
1 == 'apples'
2 == ' grapes
This is my code so far:
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
import seaborn as sns
import pandas as pd
df = pd.read_csv('embed1_2.csv')
df.loc[df.y_train == 103, 'class_name'] = 'avocados'
df.loc[df.y_train == 103, 'class_name'] = 'apples'
df.loc[df.y_train == 103, 'class_name'] = 'grapes'
How to get the appended column to show up with the converted text?
Thanks for your help!