pandas: 'join' 编译失败
pandas: 'join' failing to compile
我在尝试编译我的代码时遇到了一些问题。看起来带有 main_df = df
的行导致失败,我不太明白为什么。
非常感谢任何帮助。
import quandl
import pandas as pd
# API key was removed
api_key = 'X'
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states',flavor='html5lib')
main_df = pd.DataFrame()
for abbv in fiddy_states[0][0][1:]:
query = "FMAC/HPI_"+str(abbv)
df = quandl.get(query, authtoken=api_key)
if main_df.empty:
main_df = df
else:
main_df = main_df.join(df)
print(main_df.head())
我收到这个错误:
Traceback (most recent call last):
File "C:/Users/Dave/Documents/Python Files/helloworld.py", line 17, in
main_df = main_df.join(df)
File "C:\Python35\lib\site-packages\pandas\core\frame.py", line 4385, in join
rsuffix=rsuffix, sort=sort)
File "C:\Python35\lib\site-packages\pandas\core\frame.py", line 4399, in _join_compat
suffixes=(lsuffix, rsuffix), sort=sort)
File "C:\Python35\lib\site-packages\pandas\tools\merge.py", line 39, in merge
return op.get_result()
File "C:\Python35\lib\site-packages\pandas\tools\merge.py", line 223, in get_result
rdata.items, rsuf)
File "C:\Python35\lib\site-packages\pandas\core\internals.py", line 4445, in items_overlap_with_suffix
to_rename)
ValueError: columns overlap but no suffix specified: Index(['Value'], dtype='object')
您可以将代码列表传递给 quandl.get
函数,然后您会得到一个数据框,其中包含列中每个代码的数据。代码:
import quandl
import pandas as pd
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states', flavor='html5lib')
data = quandl.get(["FMAC/HPI_"+s for s in fiddy_states[0][0][1:]])
我在尝试编译我的代码时遇到了一些问题。看起来带有 main_df = df
的行导致失败,我不太明白为什么。
非常感谢任何帮助。
import quandl
import pandas as pd
# API key was removed
api_key = 'X'
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states',flavor='html5lib')
main_df = pd.DataFrame()
for abbv in fiddy_states[0][0][1:]:
query = "FMAC/HPI_"+str(abbv)
df = quandl.get(query, authtoken=api_key)
if main_df.empty:
main_df = df
else:
main_df = main_df.join(df)
print(main_df.head())
我收到这个错误:
Traceback (most recent call last): File "C:/Users/Dave/Documents/Python Files/helloworld.py", line 17, in main_df = main_df.join(df)
File "C:\Python35\lib\site-packages\pandas\core\frame.py", line 4385, in join rsuffix=rsuffix, sort=sort)
File "C:\Python35\lib\site-packages\pandas\core\frame.py", line 4399, in _join_compat suffixes=(lsuffix, rsuffix), sort=sort)
File "C:\Python35\lib\site-packages\pandas\tools\merge.py", line 39, in merge return op.get_result()
File "C:\Python35\lib\site-packages\pandas\tools\merge.py", line 223, in get_result rdata.items, rsuf)
File "C:\Python35\lib\site-packages\pandas\core\internals.py", line 4445, in items_overlap_with_suffix to_rename) ValueError: columns overlap but no suffix specified: Index(['Value'], dtype='object')
您可以将代码列表传递给 quandl.get
函数,然后您会得到一个数据框,其中包含列中每个代码的数据。代码:
import quandl
import pandas as pd
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states', flavor='html5lib')
data = quandl.get(["FMAC/HPI_"+s for s in fiddy_states[0][0][1:]])