0

I have the following python program test_pandas.py.

# !/usr/bin/env python3.4
# -*- coding: utf-8 -*-

import pprint

import pandas as pd
import mypandas.mypandas

df = pd.read_csv('AllStarFull.csv')

mypandas.print_pandas_df(df,50,8)

# groupby 'player ID'
print('Grouping by Player ID')
gb = df.groupby(['playerID'])
pprint.pprint(list(gb))


# groupby 'yearID'
print('Grouping by Year ID')
gb = df.groupby(['yearID'])
pprint.pprint(list(gb))

My folder structure is as follows.

--python
  --concepts
    --mypandas
      --mypandas.py
      --__init__.py
    --test_pandas.py

When I run the test_pandas.py I get the following error.

  UserWarning)
Traceback (most recent call last):
  File "C:/Cubic/playpen/python/concepts/pandas/test_pandas.py", line 11, in <module>
    mypandas.print_pandas_df(df,50,8)
AttributeError: module 'mypandas' has no attribute 'print_pandas_df'

mypandas.py has the function print_pandas_df

import pandas as pd
import pprint


def print_pandas_df(df, rows, columns):
    with pd.option_context('display.max_rows', rows, 'display.max_columns', columns):
        pprint.pprint(df)

1 Answer 1

1

You need to put the full path: directory.filename.methodname:

mypandas.mypandas.print_pandas_df(df,50,8)

You can also say

from mypandas import mypandas

and then write your code as is.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.