0

Hello I'm trying to export a pandas dataframe in a csv file but I got no clue how to do it. And I got this error 'list' object has no attribute 'to_csv'

 import pandas
pandas.set_option('display.max_rows', None)
pandas.set_option('display.max_columns', None)
pandas.set_option('display.width', None)
pandas.set_option('display.max_colwidth', -1)

from nba_api.stats.endpoints import playercareerstats

def get_player_current_year(player_id):
  career = playercareerstats.PlayerCareerStats(player_id=player_id)
  player_df = career.get_data_frames()[0]
  return player_df.loc[player_df.SEASON_ID == '2019-20',:]

player_results = []
for player_id in ['203076', '1626157', '203954', '204001', '203999']:
  player_results.append(get_player_current_year(player_id))
for result in player_results:
    print(result)

player_results.to_csv('nbatest.csv')

This how the dataframe looks like, is it because I have to merge them?

This how the dataframe looks like, is it because I have to merge them?

1

1 Answer 1

1

You have a list of dataframes instead of the dataframe. You can either to save each one of them using .to_csv() method or use pd.concat(player_results, axis=0) to concatenate them and then save it.

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

2 Comments

Can you explain further what I have to do?
It worked I forgot to put import pandas as pd with your code and worked :D

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.