• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
56 views

Problem :

I am getting bellow error
attributeerror: can only use .str accessor with string values, which use np.object_ dtype in pandas
by (6.9k points)  

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
by (33.3k points)  
...