DataFrame object has no attribute 'sample'

Alexis Eggermont

Simple code like this won't work anymore on my python shell:

import pandas as pd
df=pd.read_csv("K:/01. Personal/04. Models/10. Location/output.csv",index_col=None)
df.sample(3000)

The error I get is:

AttributeError: 'DataFrame' object has no attribute 'sample'

DataFrames definitely have a sample function, and this used to work. I recently had some trouble installing and then uninstalling another distribution of python. I don't know if this could be related.

I've previously had a similar problem when trying to execute a script which had the same name as a module I was importing, this is not the case here, and pandas.read_csv is actually working.

What could cause this?

Anand S Kumar

As given in the documentation of DataFrame.sample -

DataFrame.sample(n=None, frac=None, replace=False, weights=None, random_state=None, axis=None)

Returns a random sample of items from an axis of object.

New in version 0.16.1.

(Emphasis mine).

DataFrame.sample is added in 0.16.1 , you can either -

  1. Upgrade your pandas version to latest, you can use pip for that, Example -

    pip install pandas --upgrade
    
  2. Or if you don't want to upgrade, and want to sample few rows from the dataframe, you can also use random.sample(), Example -

    import random
    num = 100 #number of samples
    sampleddata = df.loc[random.sample(list(df.index),num)]
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

'DataFrame' object has no attribute 'sort'

From Dev

'module' object has no attribute 'DataFrame'

From Dev

AttributeError: 'DataFrame' object has no attribute

From Dev

'DataFrame' object has no attribute 'sort'

From Dev

'DataFrame' object has no attribute 'isna'

From Dev

"DataFrame" object has no attribute 'reshape'

From Dev

DataFrame object has no attribute 'sort_values'

From Dev

AttributeError: 'DataFrame' object has no attribute 'Height'

From Dev

'DataFrame' object has no attribute 'read_csv'

From Dev

Pandas: AttributeError: 'DataFrame' object has no attribute 'agg'

From Dev

Why 'DataFrame' object has no attribute 'assign'?

From Dev

Python AttributeError: 'str' object has no attribute 'DataFrame'

From Dev

pyspark AttributeError: 'DataFrame' object has no attribute 'toDF'

From Dev

AttributeError: 'DataFrame' object has no attribute 'map'

From Dev

pandas - 'dataframe' object has no attribute 'str'

From Dev

AttributeError: 'DataFrame' object has no attribute 'to_datetime'

From Dev

Pandas: AttributeError: 'DataFrame' object has no attribute 'agg'

From Dev

AttributeError: 'DataFrame' object has no attribute 'timestamp'

From Dev

Python - AttributeError: 'DataFrame' object has no attribute

From Dev

Pandas Dataframe AttributeError: 'DataFrame' object has no attribute 'design_info'

From Dev

Pandas Dataframe to SQLite - AttributeError: 'DataFrame' object has no attribute 'encode'

From Dev

TypeError: 'type' object has no attribute '__getitem__' in pandas DataFrame

From Dev

'DataFrame' object has no attribute 'ravel' when transforming target variable?

From Dev

'QueryDict' object has no attribute

From Dev

Python: object has no attribute

From Dev

Object has no attribute - HyperlinkedRelatedField

From Dev

Object has no attribute 'encode'

From Dev

"remoteContext object has no attribute"

From Dev

AttributeError: object has no attribute

Related Related

  1. 1

    'DataFrame' object has no attribute 'sort'

  2. 2

    'module' object has no attribute 'DataFrame'

  3. 3

    AttributeError: 'DataFrame' object has no attribute

  4. 4

    'DataFrame' object has no attribute 'sort'

  5. 5

    'DataFrame' object has no attribute 'isna'

  6. 6

    "DataFrame" object has no attribute 'reshape'

  7. 7

    DataFrame object has no attribute 'sort_values'

  8. 8

    AttributeError: 'DataFrame' object has no attribute 'Height'

  9. 9

    'DataFrame' object has no attribute 'read_csv'

  10. 10

    Pandas: AttributeError: 'DataFrame' object has no attribute 'agg'

  11. 11

    Why 'DataFrame' object has no attribute 'assign'?

  12. 12

    Python AttributeError: 'str' object has no attribute 'DataFrame'

  13. 13

    pyspark AttributeError: 'DataFrame' object has no attribute 'toDF'

  14. 14

    AttributeError: 'DataFrame' object has no attribute 'map'

  15. 15

    pandas - 'dataframe' object has no attribute 'str'

  16. 16

    AttributeError: 'DataFrame' object has no attribute 'to_datetime'

  17. 17

    Pandas: AttributeError: 'DataFrame' object has no attribute 'agg'

  18. 18

    AttributeError: 'DataFrame' object has no attribute 'timestamp'

  19. 19

    Python - AttributeError: 'DataFrame' object has no attribute

  20. 20

    Pandas Dataframe AttributeError: 'DataFrame' object has no attribute 'design_info'

  21. 21

    Pandas Dataframe to SQLite - AttributeError: 'DataFrame' object has no attribute 'encode'

  22. 22

    TypeError: 'type' object has no attribute '__getitem__' in pandas DataFrame

  23. 23

    'DataFrame' object has no attribute 'ravel' when transforming target variable?

  24. 24

    'QueryDict' object has no attribute

  25. 25

    Python: object has no attribute

  26. 26

    Object has no attribute - HyperlinkedRelatedField

  27. 27

    Object has no attribute 'encode'

  28. 28

    "remoteContext object has no attribute"

  29. 29

    AttributeError: object has no attribute

HotTag

Archive