因此,我尝试在 parseData 方法中打印出我的“place”的 info(),并且我需要将数据类型转换为 int64 而不是对象,而是 astype、to_numeric 和 pd.DataFrame(data=place, dtype=np。
因此,我尝试在 parseData 方法中打印出“place”的 info(),并且我需要将数据类型转换为 int64 而不是对象,但 astype、to_numeric 和 pd.DataFrame(data=place, dtype=np.int64) 都失败了
import numpy as np
import pandas as pd
year = []
month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
date = []
locationList = []
class VisitorsAnalyticsUtils:
def __init__(self):
yearPeriod = int(input("Enter year period (1: 1979-1987, 2: 1988-1997, 3: 1998-2007, 4: 2008-2017): "))
if yearPeriod not in np.array([1,2,3,4]):
print("End of Program")
quit()
else:
areaRegion = int(input("Enter region (1: Asia, 2: Europe, 3: Others): "))
if areaRegion not in np.array([1,2,3]):
print("End of Program")
quit()
else:
if yearPeriod == 1:
for x in range(9):
year.append(1979+x)
elif yearPeriod == 2:
for x in range(9):
year.append(1988+x)
elif yearPeriod == 3:
for x in range(9):
year.append(1998+x)
else:
for x in range(9):
year.append(2008+x)
areaA = np.array([ ' Brunei Darussalam ', ' Indonesia ', ' Malaysia ', ' Philippines ', ' Thailand ', ' Viet Nam ', ' Myanmar ', ' Japan ', ' Hong Kong ', ' China ', ' Taiwan ',' Korea, Republic Of ', ' India ', ' Pakistan ', ' Sri Lanka ', ' Saudi Arabia ', ' Kuwait ', ' UAE ']).tolist()
areaE = np.array([' United Kingdom ', ' Germany ', ' France ', ' Italy ', ' Netherlands ', ' Greece ', ' Belgium & Luxembourg ', ' Switzerland ', ' Austria ', ' Scandinavia ', ' CIS & Eastern Europe ']).tolist()
areaO = np.array([ ' USA ', ' Canada ', ' Australia ', ' New Zealand ', ' Africa ']).tolist()
area = [areaA, areaE, areaO]
self.yearPeriod = yearPeriod - 1
self.areaRegion = areaRegion - 1
self.year = year
self.area = area
def loadDataFile(self):
self.df = pd.read_csv('Int_Monthly_Visitor.csv', index_col=0).replace({'na':0.0}, regex=True)
print("*** first 5 row of data loaded ***")
print()
print(self.df.head())
def parseData(self):
location = self.area[self.areaRegion]
place = self.df.filter(items=location)
place = pd.DataFrame(data=place, dtype=np.int64)
print(place.info())
VAU = VisitorsAnalyticsUtils()
VAU.loadDataFile()
VAU.parseData()
为了更清晰的视野
def loadDataFile(self):
self.df = pd.read_csv('Int_Monthly_Visitor.csv', index_col=0).replace({'na':0.0}, regex=True)
print("*** first 5 row of data loaded ***")
print()
print(self.df.head())
def parseData(self):
location = self.area[self.areaRegion]
place = self.df.filter(items=location)
place = pd.DataFrame(data=place, dtype=np.int64)
print(place.info())
给出的错误是:ValueError: 以 10 为基数的 int() 的文字无效:'4,600'
我对格式和英语的混乱深感抱歉