Home > Blockchain >  module 'pandas' has no attribute 'read_csv': AttributeError
module 'pandas' has no attribute 'read_csv': AttributeError

Time:04-28

I have written a lambda function for AWS which will use pandas for handling dataframe. When I tested this lambda function - I faced error - No module name pandas. I further kept pandas and other dependencies libraries in library folder of my repository.

Now I am facing other issue which I am unable to solve.

Current error:

module 'pandas' has no attribute 'read_csv': AttributeError
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 127, in lambda_handler
    initial_df = pd.read_csv(obj['Body']) # 'Body' is a key word
AttributeError: module 'pandas' has no attribute 'read_csv'

I checked the solutions available on this site - like - module 'pandas' has no attribute 'read_csv

I don't have pandas.py and csv.py in my pandas folder but rather have test_to_csv.py, csvs.py and test_pandas.py, which is required as per the discussion in link provided above.

I am unable to figure out a way here.

CodePudding user response:

Pandas is indeed not availabel by default on AWS lambda. If you want to use Pandas with AWS lamdba, the easiest way is to use the AWS Data Wrangler layer. When you add a new layer, select AWS layers , then in the dropdown menu you can select the AWSDataWrangler-Python39 one. Once you have added the layer, you will be able to use pandas as usual.

CodePudding user response:

https://towardsdatascience.com/python-packages-in-aws-lambda-made-easy-8fbc78520e30

This helped me. Adding layers has solved the errors and also reduced my file size. Now I can edit my code inline too, which was not possible earlier.

  • Related