• Register
0 votes
2.5k views

Problem :

I am getting bellow error
attributeerror: can only use .str accessor with string values, which use np.object_ dtype in pandas
6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

As the problem statement states that you can only use .str with string columns but you have a float64. So there should not be any commas in a float so what you have will not really do anything, but you could cast it first:

dc_listings['price'].astype(str).str.replace...

For example:

In [18]: df
Out[18]:
          a         b         c         d         e
0  0.645821  0.152197  0.006956  0.600317  0.239679
1  0.865723  0.176842  0.226092  0.416990  0.290406
2  0.046243  0.931584  0.020109  0.374653  0.631048
3  0.544111  0.967388  0.526613  0.794931  0.066736
4  0.528742  0.670885  0.998077  0.293623  0.351879
9 7 4
38,600 points

Related questions

0 votes
1 answer 16 views
16 views
Problem: In my computer this error is showing by a long time, i wana to fix this problem, can anyone help me on this?
asked Apr 3 niyatiry 3.9k points
0 votes
1 answer 9 views
9 views
Problem: I am getting bellow error: attributeerror: can only use .str accessor with string values, which use np.object_ dtype in pandas
asked Mar 13 Wafa Abu Yousef 6.1k points
0 votes
0 answers 152 views
152 views
when I tried to use str.replace it gave this message dc_listings['price'].str.replace(',', '') AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas Here are the top 5 rows of my price column. This stack overflow thread ... error-can-only-use-str-accessor-with-string-values to check if my column has NAN values but non of the values in my column are NAN
asked Oct 27, 2020 psandprop 2.4k points
1 vote
1 answer 13 views
13 views
Problem : I try to create the top 5 rows of my price column. But I got this error : AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas Any ideas on what I need to do to fix this? Thanks!
asked Mar 31 Sabbir Hossain 14.6k points
0 votes
1 answer 130 views
130 views
Could anyone provide a sample of the column data that you're trying to replace? That would help a lot.
asked Dec 14, 2020 TeamScript 13.5k points
0 votes
1 answer 53 views
53 views
When writing the panda program with Str.replace method it returns an attribute error. dc_listings['price'].str.replace(',', '') AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas Shown here are the top 5 rows of my price column.
asked Nov 24, 2020 ibe4em 160 points
0 votes
1 answer 31 views
31 views
Problem: HELP! I need help understanding this error: Attributeerror: can only use .dt accessor with datetimelike values..
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
0 answers 171 views
171 views
import cv2, time, pandas import numpy as np from termcolor import colored import datetime import pandas as pd import matplotlib.pyplot as plt import os import pyautogui from bokeh.plotting import figure, show, output_file from bokeh.models import HoverTool, ColumnDataSource first_frame = None ... ).strftime("%Y-%m-%d_%H%M%S")+".html") show(p) #plt.savefig('plot.pdf', dpi=300, bbox_inches='tight')
asked Jun 13, 2020 Shivi Trivedi
2 votes
1 answer 3.2K views
3.2K views
Problem : I am very new to Python and Pandas. Currently I am learning to use the Pandas so that I can convert my column to month. When I try to read my data then they are objects. So I am first of all trying to make them to the date time and ... " 2529 "values") 2530 AttributeError: Can only use .dt accessor with datetimelike values Looking for help from Pandas expert to fix my above error.
asked Apr 29, 2020 stewart 4k points
0 votes
1 answer 56 views
56 views
Problem: I got the data column: print(df["Hour"]) Hour 0 01:21:46 1 01:22:16 2 01:22:46 3 01:25:16 4 01:25:46 It says the column type is an object, but when I try to convert from pd.to_datetime, it says TypeError: <class 'datetime.time'> is ... to minutes, so I tried with df["Hour"].dt.seconds, but it shows an error:AttributeError: Can only use .dt accessor with datetimelike values. Hel, please!
asked Jan 1 sasha 16.2k points