Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

split the column value and take first value in pandas

import pandas as pd
import numpy as np
df = pd.DataFrame({'Geek_ID':['Geek1_id', 'Geek2_id', 'Geek3_id', 
                                         'Geek4_id', 'Geek5_id'],
                'Geek_A': [1, 1, 3, 2, 4],
                'Geek_B': [1, 2, 3, 4, 6],
                'Geek_R': np.random.randn(5)})
  
# Geek_A  Geek_B   Geek_ID    Geek_R
# 0       1       1  Geek1_id    random number
# 1       1       2  Geek2_id    random number
# 2       3       3  Geek3_id    random number
# 3       2       4  Geek4_id    random number
# 4       4       6  Geek5_id    random number
  
print(df.Geek_ID.str.split('_').str[0])
Comment

PREVIOUS NEXT
Code Example
Python :: convert string to int dataframe column 
Python :: list all files in python 
Python :: check list for duplicate values python 
Python :: python keyboard 
Python :: how to improve accuracy of random forest classifier 
Python :: shuffle text lines python 
Python :: how to add a column with more rows to a dataframe 
Python :: python combinations 
Python :: python check if key exist in json 
Python :: python tobytes 
Python :: python namedtuples 
Python :: get first letter of each word in string python 
Python :: remove french stopwords with spacy 
Python :: first and last name generator python 
Python :: Convert datetime object to a String of date only in Python 
Python :: if and else in python 
Python :: lucky number codechef solution 
Python :: how to change the name of a variable in a loop python 
Python :: how to add value in array django 
Python :: edit path variable using python 
Python :: class inside class python 
Python :: dict to string 
Python :: teardown module pytest 
Python :: test django migrations without applying them 
Python :: opencv webcam 
Python :: request post python with api key integration 
Python :: head first python 
Python :: indentation in python 
Python :: adding strings together 
Python :: prevent selenium from closing 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =