I have a Pandas series of 10,000 lines that is filled with one alphabet, starting from A to Z. However, I want to create dummy data frames for A, B and C only using Pandas get_dummies . How do I get around this?
Pandas
get_dummies
I donβt want to get dummies for all the row values ββin a column, and then select specific columns, since the column contains other redundant data that ultimately leads to a memory error.
try the following:
# create mock dataframe df = pd.DataFrame( {'alpha':['a','a','b','b','c','e','f','g']}) # use replace with a regex to set characters dz to None pd.get_dummies(df.replace({'[^ac]':None},regex =True))
output:
alpha_a alpha_b alpha_c 0 1 0 0 1 1 0 0 2 0 1 0 3 0 1 0 4 0 0 1 5 0 0 0 6 0 0 0 7 0 0 0
Source: https://habr.com/ru/post/1235138/More articles:Vibrating Phone at UWP - c #Multiple migration statements in a single migration file - node.jsMySql timestamp - different time after updating all rows - phpWhy does this recursive code generate segfault? - cHow to read a zip file from a remote URL without extracting it - javaCombining AngularJS, jQueryUI, Angular -Drag-Drop for a sorted list - javascriptHow to make an index point for two or more consecutive cells - cAdd a parameter to the query string of all URLs loaded in WKWebView - query-stringhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1235142/ejabberd-httplocalhost5280-redirects-to-wwwlocalhostcom5280&usg=ALkJrhhpzNfBJfH4Pq4l95vXM-01tfp-Iwhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1235143/apply-a-stream-of-mappers-to-another-stream-in-java8&usg=ALkJrhiqH1z_DK3fv0_tZpbMKqrExknbEgAll Articles