• Register
0 votes
1.8k 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
0 answers 29 views
29 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
0 votes
1 answer 11 views
11 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 9.5k points
0 votes
1 answer 16 views
16 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
0 answers 97 views
97 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 2.4K views
2.4K 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 13 views
13 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 5.3k points
0 votes
1 answer 4.5K views
4.5K views
Problem : I have the pandas data frame with some of the categorical predictors or variables as 0 & 1, and some of the numeric variables. When I fit that to a stasmodel like below : est = sm.OLS(y, X).fit() It throws the below error : Pandas data ... hundreds of variables. For that I have concatenated the 3 pandas DataFrames to come up with the final DataFrame to be used in the model building.
asked Dec 18, 2019 alecxe 7.5k points
0 votes
1 answer 2.3K views
2.3K views
Problem : I have the two DataFrames which I would want to merge. I have referred many documents and also tried to perform many operations but I am not sure what to do now. Please find my two DataFrames as below: DataFrame1: id name type currency 0 BTTA.S Apple ... here I met with the exception as below : ValueError: can not merge DataFrame with instance of type <class 'pandas.core.series.Series'>
asked Dec 24, 2019 alecxe 7.5k points
0 votes
1 answer 10 views
10 views
Problem: I have the following dataframe time X Y X_t0 X_tp0 X_t1 X_tp1 X_t2 X_tp2 0 0.002876 0 10 0 NaN NaN NaN NaN NaN 1 0.002986 0 10 0 NaN 0 NaN NaN NaN 2 0.037367 1 10 1 1.000000 0 NaN 0 NaN 3 0.037374 2 10 2 0.500000 1 1.000000 0 ... value too large for dtype('float32').whenever I try to fit the regression modelfit(X_train, y_train) How can we remove both values NaNand -infat the same time?
asked Dec 24, 2020 sasha 5.3k points
0 votes
1 answer 27 views
27 views
Problems I am trying to update selected datetime64 values in a pandas data frame using the loc method to select rows satisfying a condition. However, instead of assigning the new date-time value it results in NaT. Here is a simplification of my code that shows the problem: ... as the second element in the new_date column. Any ideas on how this should be done or why this is not working as intended?
asked Sep 15, 2020 Marivoke 530 points