0
$\begingroup$
df = pd.DataFrame([
['Africa', 'Egypt', 0, 0,155490,1,0.115],
['Africa', 'Kenya', 78182, 7,291210,1,0.45],
['Asia Pacific (excludes Greater China)', 'India', 667657, 1,0,-0.650],
['Asia Pacific (excludes Greater China)', 'Vietnam', 0, 0,0,0,0.005]
])
df.columns = ['Subregion', 'Market', 'Q4 2017', 'Rank_2017','Q4 2018','Rank_2018','year on Year Growth']

I just made up the data in actuality there are much more columns and rows but I Want to know how can I encode these Subregion and Market columns using one-hot encoding or any other way or method or library or work around anything that would do

$\endgroup$
4
  • $\begingroup$ Maybe this can help you : datascience.stackexchange.com/a/79575/101580 $\endgroup$
    – Adept
    Jul 21, 2022 at 10:27
  • $\begingroup$ What is the objective? Maybe, in some cases, it is not categories but rather labels. $\endgroup$ Jul 22, 2022 at 8:13
  • $\begingroup$ so my objective was to encode these columns using one hot encoding so I tried and did it but it gave me a 1D array that was not acceptable by the regression to train itself had it been a single column these would have been really easy but here we have 2 column that has categorical data and m not able to perform the learning on these datasets $\endgroup$ Jul 22, 2022 at 17:32
  • $\begingroup$ It's normal that the one-hot encoding (OHE) gives you an array of features, this is exactly how OHE works. One must concatenate these features to the other features in order to provide a one-dimension array of features for every instance. Also don't forget to use @somebody when you want to reply to a comment, otherwise the other person is not notified. $\endgroup$
    – Erwan
    Jul 25, 2022 at 8:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.