2016-09-22 8 views
0

私は次のPythonプログラムtest_pandas.pyを持っています。AttributeError:モジュール 'mypandas'に 'print_pandas_df'属性がありません

# !/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)) 

私のフォルダ構造は次のとおりです。

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

私は、私は次のエラーを取得するtest_pandas.pyを実行します。

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あなたは完全なパスを配置する必要があり機能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

がありますdirectory.filename.methodname:

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

また

from mypandas import mypandas 
を言うことができます

あなたのコードをそのまま書いてください。

関連する問題