My pandas dataframe is very large and so I want to be able to modify the textLower(frame) function so that it gets executed in one command and I dont have to iterate over each row to perform a sequence of string manipulations over each element.
# Function iterates over all the values of a pandas dataframe
def textLower(frame):
for index, row in frame.iterrows():
row['Text'] = row['Text'].lower()
# further modification on row['Text']
return frame
def tryLower():
cities = ['Chicago', 'New York', 'Portland', 'San Francisco',
'Austin', 'Boston']
dfCities = pd.DataFrame(cities, columns=['Text'])
frame = textLower(dfCities)
for index, row in frame.iterrows():
print(row['Text'])
######################### main () #########################
def main():
tryLower()
Try this:
dfCities["Text"].str.lower()
or this:
def textLower(x):
return x.lower()
dfCities = dfCities["Text"].apply(textLower)
dfCities
# 0 chicago
# 1 new york
# 2 portland
# 3 san francisco
# 4 austin
# 5 boston
# Name: Text, dtype: object
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With