我在想怎么从我的csv fi上去掉逗号和美元符号

2024-06-26 01:36:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在与csv文件处理工资。我想去掉美元符号和逗号,这样我就可以把字符串转换成整数

import csv
import numpy as np
import random
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt

phillies_of = pd.read_csv('/Users/hannahbeegle/Desktop/Teams/PHILLIES.csv', header = None)
phillies_pr = pd.read_csv('/Users/hannahbeegle/Desktop/Teams/PHILLIES_PR.csv',header = None)

phillies_pr.loc[:,7]= phillies_pr.loc[:,7].replace('$','')
phillies_pr.loc[:,7]= phillies_pr.loc[:,7].replace(',','')
filter = phillies_pr.loc[:,7]= ''
phillies_pr.where(filter).dropna()
fan_attendance = [int(i) for i in phillies_pr.iloc[:,7]]

ERROR MESSAGE:
Traceback (most recent call last):
  File "/Users/hannahbeegle/Desktop/Text Files/TeamDataBase.py", line 68, in <module>
    phillies_pr.where(filter).dropna()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 8834, in where
    errors=errors, try_cast=try_cast)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 8572, in _where
    raise ValueError('Array conditional must be same shape as '
ValueError: Array conditional must be same shape as self

Tags: csvinimportpandasasprfilterwhere