Python Forum
Trying to search and make new column from the keyword.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to search and make new column from the keyword.
#1
Below is the code - I am trying to add new column as name - keywords and data frame name is qd1 and column name is CRTXT
The error I am getting is
Error:
: 'float' object has no attribute 'upper'()


def keyword(row):
  strings = row['CRTXT']
  keywords =  ["stopped working","quit working","didnt like","stop working","not working"]
  keyword = [key for key in keywords if key.upper() in strings.upper()]
  return ','.join(keyword)


df1 = pd.DataFrame(qd1,columns = ['CRTXT'])
df1['keyword'] = df1.apply(keyword, axis=1)
Gribouillis write Dec-20-2021, 07:11 PM:
lease post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply
#2
The error says that you have a float number in df1 which means you have a float number in qd1. From the screenshot this must be between rows 4 and 73511. The code below has the same problem, crashing when it tries to call (2.0).upper().
import pandas as pd

df1 = pd.DataFrame(["-", "+", "1", 2.0], columns=["CRTXT"])
for x in df1['CRTXT']:
    print(x, ', ', sep="", end="")
    print(x.upper())
Output:
-, - +, + 1, 1 2.0, Traceback (most recent call last): File "...", line 6, in <module> print(x.upper()) AttributeError: 'float' object has no attribute 'upper'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a specific keyword after another keyword and change the output sgtmcc 5 818 Oct-05-2023, 07:41 PM
Last Post: deanhystad
  How do I make a symmetric matrix from a column vector? leocsmith 3 3,684 Mar-30-2021, 10:17 AM
Last Post: leocsmith
  Openpyxl tkinter search a value in Excel column Heathcliff_1 0 3,264 Dec-02-2020, 04:35 PM
Last Post: Heathcliff_1
  how to make a keyword arg w/o a default value? Skaperen 10 3,550 Jun-30-2020, 01:55 AM
Last Post: Skaperen
  search binary file and list all founded keyword offset Pyguys 4 2,774 Mar-17-2020, 06:46 AM
Last Post: Pyguys
  how to make iterative search more efficient renergy 2 2,271 Jan-03-2020, 03:43 PM
Last Post: stullis
  Search Excel column values jonzee 1 2,599 Dec-21-2019, 02:38 AM
Last Post: Clunk_Head
  Trying to make column based file from text file scor1pion 7 3,479 Jul-16-2019, 02:43 PM
Last Post: scor1pion
  How can I make a faster search algorithm pianistseb 19 6,578 Apr-18-2019, 05:48 PM
Last Post: Larz60+
  SQLite Query multiple column search whacky7 6 8,394 Apr-01-2019, 09:29 PM
Last Post: whacky7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020