AttributeError:module 'pandas' has no attribute 'read_csv' troubleshooting

Asked 2 years ago, Updated 2 years ago, 42 views

The following error will appear:

Traceback (most recent call last):
  File "", line 7, in <module>
    df=pd.read_csv(u'Nihon Keizai Average_2014.csv', encoding='shift-jis')
AttributeError: module 'pandas' has no attribute 'read_csv'

Here's the code.

import numpy as np
import pandas aspd

# [[Short-term, long-term] [Short-term, long-term]
types=[5,25],[25,75],[13,26]]

df=pd.read_csv(u'Nihon Keizai Average_2014.csv', encoding='shift-jis')
df=df.sort_values(by=u'date') .reset_index(drop=True)

for short_day, long_day intypes:

    # moving average
    rolling_s = df [u' closing value '].rolling(short_day).mean().fillna(0)
    rolling_l = df [u' closing value '].rolling(long_day).mean().fillna(0)

    # cross-checking of moving average
    over_s_l = rolling_s>rolling_l
    golden=(over_s_l!=over_s_l.shift(1))&(over_s_l==True)
    dead=(over_s_l!=over_s_l.shift(1))&(over_s_l==False)

    # column addition
    #   0—No cross
    #   1: Golden Cross
    #  -1: Dead Cross
    col_name='cross_'+str(short_day)+'_'+str(long_day)
    df[col_name] = [x+y*-1 for x, y in zip(golden, dead)]
    df[col_name] = np.append(np.array([0]*(long_day+1)), df[col_name][long_day+1:])
    #

python pandas

2022-09-30 20:21

1 Answers

I think there is pandas.py in the current directory and it is loaded.


2022-09-30 20:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.