2021年2月6日星期六

Cannot load data from spreadsheet properly

I have a spreadsheet looking like this:

|Symbol | Name | |A |

I'm trying to read it into dataframe:

def loading_nasdaq_info_from_spreadsheet():      excel_file = 'nasdaq.xlsx'      nasdaq_info_dataframe = pandas.read_excel(excel_file, index_col=0)      # data cleaning      nasdaq_info_dataframe.dropna()        return nasdaq_info_dataframe      if __name__ == '__main__':      df = loading_nasdaq_info_from_spreadsheet()      print(df.loc['symbol'])  

I constantly get

"raise KeyError(key) from err KeyError: 'Symbol'"

It doesn't matter which key I wanna print or use. It is always the same error. What's even worse, even I manually (in excel) set everything to text, when I'm trying to

nasdaq_info_dataframe.applymap(lambda text: text.strip())  

I get

'float' doesn't have strip()

I fight with this for a few hours now, so please help me.

EDIT:

Printing

print(df.loc)  

gives

<pandas.core.indexing._LocIndexer object at 0x1160e8778>

https://stackoverflow.com/questions/66083564/cannot-load-data-from-spreadsheet-properly February 07, 2021 at 09:01AM

没有评论:

发表评论