I am having an issue with pandas reading my data file. The relevant code I'm using at the moment is this:
import pandas as pd
file_data = pd.read_csv('14_May_2022.csv')
complete_df = pd.DataFrame(file_data)
print(complete_df.info())
Current_Players_df = complete_df[["Game","Current_Players"]]
print(Current_Players_df)
print("The average current players is:\n")
print(Current_Players_df["Current_Players"].mean())`
when I try to run this all is fine until the last line of code where I get a lengthy error code beginning with:
Traceback (most recent call last):
File "C:\Users\christy\AppData\Roaming\Python\Python37\site-packages\pandas\core\nanops.py", line 1603, in _ensure_numeric
x = float(x)
ValueError: could not convert string to float:
and then going on to list every value (which are all numbers)
I have tried two possible solutions but neither work. These are the ones I've tried:
complete_df['Current_Players']= pd.to_numeric(complete_df['Current_Players'].astype(str).str.strip(),error='coerce')
The error message shows:
Traceback (most recent call last):
File "C:\Users\christy\OneDrive\Documents\steam data analysis\analysis.py", line 6, in <module>
complete_df['Current_Players']= pd.to_numeric(complete_df['Current_Players'].astype(str).str.strip(),error='coerce')
TypeError: to_numeric() got an unexpected keyword argument 'error'
str.strip(complete_df['Current_Players'])
The error message shows:
Traceback (most recent call last):
File "C:\Users\christy\OneDrive\Documents\steam data analysis\analysis.py", line 7, in <module>
str.strip(complete_df['Current_Players'])
TypeError: descriptor 'strip' requires a 'str' object but received a 'Series'