logo
down
shadow

How to split a Column when you have same values?


How to split a Column when you have same values?

By : Nero
Date : October 24 2020, 06:10 AM
Any of those help Use Series.str.split and if necessary remove second column by drop:
code :
df1 = df['Column1'].str.split('::', expand=True).drop(1, axis=1)
df1 = df['Column1'].str.split('::Charm::', expand=True)
df1.columns = ['Col1','Col2']
print (df1)
             Col1    Col2
0   InitialCharms  AAAAAA
1   InitialCharms  BBBBBB
2   InitialCharms  CCCCCC
3   InitialCharms  DDDDDD
4   InitialCharms  EEEEEE
5   InitialCharms  FFFFFF
6   InitialCharms  GGGGGG
7   InitialCharms  HHHHHH
8   InitialCharms  IIIIII
9   InitialCharms  JJJJJJ
10  InitialCharms  KKKKKK
11  InitialCharms  LLLLLL


Share : facebook icon twitter icon
How to split a single column values to multiple column values?

How to split a single column values to multiple column values?


By : user2776995
Date : March 29 2020, 07:55 AM
Hope that helps I have a problem splitting single column values to multiple column values. , Your approach won't deal with lot of names correctly but...
code :
SELECT CASE
         WHEN name LIKE '% %' THEN LEFT(name, Charindex(' ', name) - 1)
         ELSE name
       END,
       CASE
         WHEN name LIKE '% %' THEN RIGHT(name, Charindex(' ', Reverse(name)) - 1)
       END
FROM   YourTable 
how to split single column values into multiple columns based on other column values

how to split single column values into multiple columns based on other column values


By : user2697146
Date : March 29 2020, 07:55 AM
To fix the issue you can do I am trying to split single column values into multiple columns based on another column value, I could get it but I am unable to remove the additional null values I get , Check the below script and hope this help you:
code :
Select t1.strValue , t2.strvalue from tbl1 t1 inner join tbl1 t2 on t1.id = t2.id 
where t1.strtype = 'name' and t2.strtype = 'value' and t1.strvalue = LEFT(t2.strvalue ,1) 
using split() to split values in an entire column in a python dataframe

using split() to split values in an entire column in a python dataframe


By : user2950601
Date : November 17 2020, 11:55 AM
wish help you to fix your issue You need to do the following, so call .str.split on the column and then .str[0] to access the first portion of the split string of interest:
code :
In [6]:

df['csuristem'].str.split('.').str[0]
Out[6]:
0    /gradoffice/index
1    /gradoffice/index
2    /gradoffice/index
3    /gradoffice/index
Name: csuristem, dtype: object
How to Split a Column in Data-frame and add the split values

How to Split a Column in Data-frame and add the split values


By : Nguji1
Date : March 29 2020, 07:55 AM
Hope this helps I have a Data-frame with column "age" of type String,I want to change values in following form. , You can write a simple UDF function to get the result
code :
val scrubUdf = udf((value : String ) => {
  value match {
    case "NaN"  => 0
    case "null" => 999
    case null   => 999
    case x if x.contains("-") => {
      //          (value.split("-")(0).toInt + value.split("-")(1).toInt) / 2
      x.split("-").map(x=> x.toInt).sum / 2
    }
    case x if x.toInt >= 200 => 999
    case _ => value.toInt
  }
})
   df.withColumn("newAge", scrubUdf($"Age"))
How to split a column into alphabetic values and numeric values from a column in a Pandas dataframe?

How to split a column into alphabetic values and numeric values from a column in a Pandas dataframe?


By : Knut Hering
Date : March 29 2020, 07:55 AM
this will help Use str.replace with str.extract by [A-Z]+ for all uppercase strings:
code :
df['Section_Number'] = df['Section'].str.replace('([A-Z]+)', '')
df['Section_Letter'] = df['Section'].str.extract('([A-Z]+)')
print (df)
    Name Section Section_Number Section_Letter
1  James      P3              3              P
2    Sam    2.5C            2.5              C
3  Billy     T35             35              T
4  Sarah     A85             85              A
5  Felix      5I              5              I
df['Section_Number'] = df['Section'].str.replace('([A-Za-z]+)', '')
df['Section_Letter'] = df['Section'].str.extract('([A-Za-z]+)')
print (df)
    Name Section Section_Number Section_Letter
1  James      P3              3              P
2    Sam    2.5C            2.5              C
3  Billy     T35             35              T
4  Sarah     A85             85              A
5  Felix      5I              5              I
Related Posts Related Posts :
  • Percent signs in windows path
  • How to add a random number to a subsection of a numpy array?
  • How to generate all the values of an iterable besides the last few?
  • Searching by both class and range in XPath
  • Python code execution in Perl interpreter
  • Best Way to Include Variable in Python3
  • Serialize the @property methods in a Python class
  • What is the most platform- and Python-version-independent way to make a fast loop for use in Python?
  • Good way to edit the previous defined class in ipython
  • Bounced email on Google App Engine
  • Search jpeg files using python
  • Dynamically create class attributes
  • python unichr problem
  • Python beginner, strange output problem
  • Python: Finding a value in 1 list and finding that corresponding index in another list
  • can't install mysqlclient on mac os x mojave
  • Error indicates flattened dimensions when loading pre-trained network
  • how to replace underlines with words?
  • Adding through iteration
  • Use OpenCV on deployed Flask app (Heroku)
  • How to skip interstitial in a django view if a user hits the back button?
  • Any Naive Bayesian Classifier in python?
  • Python 2.5.2: remove what found between two lines that contain two concrete strings
  • Python 2.5.2 script that add "The function starts here" to all the functions of the files of a directory
  • HttpResponseRedirect question
  • Python socket error on UDP data receive. (10054)
  • Encoding issues with cloud ml
  • numpy.where - Weird behaviour: new elements spawning from nowhere?
  • I can't move my player in pygame, can you figure why?
  • Weird error I receive from Tkinter in Python
  • Using a Zapier Custom Request Webhook with JSON Web Tokens
  • Keras: Use categorical_crossentropy without one-hot encoded array of targets
  • Does python's httplib.HTTPConnection block?
  • Do alternate python implementation version numbers imply that they provide the same syntax?
  • Searching for specific HTML string using Python
  • python sax error "junk after document element"
  • MySql: How to know if an entry is compressed or not
  • Return a list of imported Python modules used in a script?
  • Returning a list in this recursive coi function in python
  • Python2.6 Decimal to Octal
  • Appengine Apps Vs Google bot web crawler
  • Changing models in django results in broken database?
  • Global variable functions
  • Using lambda inside a function
  • How to open a file, replace some strings, and save updates to the same file?
  • How to move the beginning of an input to the and?
  • If else fill variable if empty list
  • Pandas: Find and print all floats in column
  • sqlite3.OperationalError: database is locked - non-threaded application
  • How to implement mib module in net-snmp with python?
  • Does Python/Scipy have a firls( ) replacement (i.e. a weighted, least squares, FIR filter design)?
  • sorl-thumbnail and file renaming
  • Python -- what is NOT in 2.7 that IS in 3.1? So many things have been back-ported, what is NOT?
  • How to make a Django model fields calculated at runtime?
  • Django - Threading in views without hanging the server
  • Python: Why is my POST requests not working?
  • Tried to add a value to a while condition, but it doesn't go back
  • How do I exit a while-true loop after 5 tries?
  • win python3 Multithreading
  • Compare 2 dictionaries in python
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk