Private
Public Access
1
0

replacing a few ix with loc.iloc

This commit is contained in:
Sander Roosendaal
2019-02-07 10:08:26 +01:00
parent ca6e7746b7
commit 00643f2705
5 changed files with 57 additions and 57 deletions

View File

@@ -118,11 +118,11 @@ def get_latlon(id):
rowdata = rdata(w.csvfilename)
try:
try:
latitude = rowdata.df.ix[:, ' latitude']
longitude = rowdata.df.ix[:, ' longitude']
latitude = rowdata.df.loc[:, ' latitude']
longitude = rowdata.df.loc[:, ' longitude']
except KeyError:
latitude = 0 * rowdata.df.ix[:, 'TimeStamp (sec)']
longitude = 0 * rowdata.df.ix[:, 'TimeStamp (sec)']
latitude = 0 * rowdata.df.loc[:, 'TimeStamp (sec)']
longitude = 0 * rowdata.df.loc[:, 'TimeStamp (sec)']
return [latitude, longitude]
except AttributeError:
return [pd.Series([]), pd.Series([])]
@@ -964,7 +964,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
totaltime = row.df['TimeStamp (sec)'].max(
) - row.df['TimeStamp (sec)'].min()
try:
totaltime = totaltime + row.df.ix[0, ' ElapsedTime (sec)']
totaltime = totaltime + row.df.loc[:, ' ElapsedTime (sec)'].iloc[0]
except KeyError:
pass
@@ -2077,37 +2077,37 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
return 0
rowdatadf.set_index([range(len(rowdatadf))], inplace=True)
t = rowdatadf.ix[:, 'TimeStamp (sec)']
t = pd.Series(t - rowdatadf.ix[0, 'TimeStamp (sec)'])
t = rowdatadf.loc[:, 'TimeStamp (sec)']
t = pd.Series(t - rowdatadf.loc[:, 'TimeStamp (sec)'].iloc[0])
row_index = rowdatadf.ix[:, ' Stroke500mPace (sec/500m)'] > 3000
row_index = rowdatadf.loc[:, ' Stroke500mPace (sec/500m)'] > 3000
rowdatadf.loc[row_index, ' Stroke500mPace (sec/500m)'] = 3000.
p = rowdatadf.ix[:, ' Stroke500mPace (sec/500m)']
p = rowdatadf.loc[:, ' Stroke500mPace (sec/500m)']
try:
velo = rowdatadf.ix[:,' AverageBoatSpeed (m/s)']
velo = rowdatadf.loc[:,' AverageBoatSpeed (m/s)']
except KeyError:
velo = 500./p
hr = rowdatadf.ix[:, ' HRCur (bpm)']
spm = rowdatadf.ix[:, ' Cadence (stokes/min)']
cumdist = rowdatadf.ix[:, 'cum_dist']
power = rowdatadf.ix[:, ' Power (watts)']
averageforce = rowdatadf.ix[:, ' AverageDriveForce (lbs)']
drivelength = rowdatadf.ix[:, ' DriveLength (meters)']
hr = rowdatadf.loc[:, ' HRCur (bpm)']
spm = rowdatadf.loc[:, ' Cadence (stokes/min)']
cumdist = rowdatadf.loc[:, 'cum_dist']
power = rowdatadf.loc[:, ' Power (watts)']
averageforce = rowdatadf.loc[:, ' AverageDriveForce (lbs)']
drivelength = rowdatadf.loc[:, ' DriveLength (meters)']
try:
workoutstate = rowdatadf.ix[:, ' WorkoutState']
workoutstate = rowdatadf.loc[:, ' WorkoutState']
except KeyError:
workoutstate = 0 * hr
peakforce = rowdatadf.ix[:, ' PeakDriveForce (lbs)']
peakforce = rowdatadf.loc[:, ' PeakDriveForce (lbs)']
forceratio = averageforce / peakforce
forceratio = forceratio.fillna(value=0)
try:
drivetime = rowdatadf.ix[:, ' DriveTime (ms)']
recoverytime = rowdatadf.ix[:, ' StrokeRecoveryTime (ms)']
drivetime = rowdatadf.loc[:, ' DriveTime (ms)']
recoverytime = rowdatadf.loc[:, ' StrokeRecoveryTime (ms)']
rhythm = 100. * drivetime / (recoverytime + drivetime)
rhythm = rhythm.fillna(value=0)
except:
@@ -2152,7 +2152,7 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
else:
drivenergy = drivelength * averageforce
distance = rowdatadf.ix[:, 'cum_dist']
distance = rowdatadf.loc[:, 'cum_dist']
velo = 500. / p
distanceperstroke = 60. * velo / spm
@@ -2184,26 +2184,26 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
if bands:
# HR bands
data['hr_ut2'] = rowdatadf.ix[:, 'hr_ut2']
data['hr_ut1'] = rowdatadf.ix[:, 'hr_ut1']
data['hr_at'] = rowdatadf.ix[:, 'hr_at']
data['hr_tr'] = rowdatadf.ix[:, 'hr_tr']
data['hr_an'] = rowdatadf.ix[:, 'hr_an']
data['hr_max'] = rowdatadf.ix[:, 'hr_max']
data['hr_ut2'] = rowdatadf.loc[:, 'hr_ut2']
data['hr_ut1'] = rowdatadf.loc[:, 'hr_ut1']
data['hr_at'] = rowdatadf.loc[:, 'hr_at']
data['hr_tr'] = rowdatadf.loc[:, 'hr_tr']
data['hr_an'] = rowdatadf.loc[:, 'hr_an']
data['hr_max'] = rowdatadf.loc[:, 'hr_max']
data['hr_bottom'] = 0.0 * data['hr']
try:
tel = rowdatadf.ix[:, ' ElapsedTime (sec)']
tel = rowdatadf.loc[:, ' ElapsedTime (sec)']
except KeyError:
rowdatadf[' ElapsedTime (sec)'] = rowdatadf['TimeStamp (sec)']
if barchart:
# time increments for bar chart
time_increments = rowdatadf.ix[:, ' ElapsedTime (sec)'].diff()
time_increments = rowdatadf.loc[:, ' ElapsedTime (sec)'].diff()
try:
time_increments.ix[0] = time_increments.ix[1]
time_increments.iloc[0] = time_increments.iloc[1]
except KeyError:
time_increments.ix[0] = 1.
time_increments.iloc[0] = 1.
time_increments = 0.5 * time_increments + 0.5 * np.abs(time_increments)
x_right = (t2 + time_increments.apply(lambda x: timedeltaconv(x)))
@@ -2212,28 +2212,28 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
if empower:
try:
wash = rowdatadf.ix[:, 'wash']
wash = rowdatadf.loc[:, 'wash']
except KeyError:
wash = 0 * power
try:
catch = rowdatadf.ix[:, 'catch']
catch = rowdatadf.loc[:, 'catch']
except KeyError:
catch = 0 * power
try:
finish = rowdatadf.ix[:, 'finish']
finish = rowdatadf.loc[:, 'finish']
except KeyError:
finish = 0 * power
try:
peakforceangle = rowdatadf.ix[:, 'peakforceangle']
peakforceangle = rowdatadf.loc[:, 'peakforceangle']
except KeyError:
peakforceangle = 0 * power
if data['driveenergy'].mean() == 0:
try:
driveenergy = rowdatadf.ix[:, 'driveenergy']
driveenergy = rowdatadf.loc[:, 'driveenergy']
except KeyError:
driveenergy = power * 60 / spm
else:
@@ -2246,7 +2246,7 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
drivelength = driveenergy / (averageforce * 4.44822)
try:
slip = rowdatadf.ix[:, 'slip']
slip = rowdatadf.loc[:, 'slip']
except KeyError:
slip = 0 * power
@@ -2319,11 +2319,11 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
if otwpower:
try:
nowindpace = rowdatadf.ix[:, 'nowindpace']
nowindpace = rowdatadf.loc[:, 'nowindpace']
except KeyError:
nowindpace = p
try:
equivergpower = rowdatadf.ix[:, 'equivergpower']
equivergpower = rowdatadf.loc[:, 'equivergpower']
except KeyError:
equivergpower = 0 * p + 50.

View File

@@ -103,7 +103,7 @@ def getsinglecp(df):
dfnew = pd.DataFrame({
'time':1000*(df['TimeStamp (sec)']-df.ix[0,'TimeStamp (sec)']),
'time':1000*(df['TimeStamp (sec)']-df.loc[:,'TimeStamp (sec)'].iloc[0]),
'power':df[' Power (watts)']
})

View File

@@ -4,7 +4,7 @@ pytestmark = pytest.mark.django_db
from bs4 import BeautifulSoup
import re
from nose_parameterized import parameterized
from parameterized import parameterized
from django.test import TestCase, Client,override_settings, RequestFactory, TransactionTestCase
from django.core.management import call_command

Binary file not shown.

View File

@@ -1757,35 +1757,35 @@ def add_workout_from_strokedata(user,importid,data,strokedata,
unixtime = cum_time+starttimeunix
# unixtime[0] = starttimeunix
seconds = 0.1*strokedata.ix[:,'t']
seconds = 0.1*strokedata.loc[:,'t']
nr_rows = len(unixtime)
try:
latcoord = strokedata.ix[:,'lat']
loncoord = strokedata.ix[:,'lon']
latcoord = strokedata.loc[:,'lat']
loncoord = strokedata.loc[:,'lon']
except:
latcoord = np.zeros(nr_rows)
loncoord = np.zeros(nr_rows)
try:
strokelength = strokedata.ix[:,'strokelength']
strokelength = strokedata.loc[:,'strokelength']
except:
strokelength = np.zeros(nr_rows)
dist2 = 0.1*strokedata.ix[:,'d']
dist2 = 0.1*strokedata.loc[:,'d']
try:
spm = strokedata.ix[:,'spm']
spm = strokedata.loc[:,'spm']
except KeyError:
spm = 0*dist2
try:
hr = strokedata.ix[:,'hr']
hr = strokedata.loc[:,'hr']
except KeyError:
hr = 0*spm
pace = strokedata.ix[:,'p']/10.
pace = strokedata.loc[:,'p']/10.
pace = np.clip(pace,0,1e4)
pace = pace.replace(0,300)
@@ -7967,7 +7967,7 @@ def workout_downloadwind_view(request,id=0,
return HttpResponse("Error: CSV Data File Not Found")
try:
bearing = rowdata.df.ix[:,'bearing'].values
bearing = rowdata.df.loc[:,'bearing'].values
except KeyError:
rowdata.add_bearing()
rowdata.write_csv(f1,gzip=True)
@@ -7976,7 +7976,7 @@ def workout_downloadwind_view(request,id=0,
try:
avglat = rowdata.df[' latitude'].mean()
avglon = rowdata.df[' longitude'].mean()
avgtime = int(rowdata.df['TimeStamp (sec)'].mean()-rowdata.df.ix[0,'TimeStamp (sec)'])
avgtime = int(rowdata.df['TimeStamp (sec)'].mean()-rowdata.df.loc[:,'TimeStamp (sec)'].iloc[0])
startdatetime = dateutil.parser.parse("{}, {}".format(row.date,
row.starttime))
@@ -8033,7 +8033,7 @@ def workout_downloadmetar_view(request,id=0,
return HttpResponse("Error: CSV Data File Not Found")
try:
bearing = rowdata.df.ix[:,'bearing'].values
bearing = rowdata.df.loc[:,'bearing'].values
except KeyError:
rowdata.add_bearing()
rowdata.write_csv(f1,gzip=True)
@@ -8043,7 +8043,7 @@ def workout_downloadmetar_view(request,id=0,
avglat = rowdata.df[' latitude'].mean()
avglon = rowdata.df[' longitude'].mean()
airportcode = get_airport_code(avglat,avglon)[0]
avgtime = int(rowdata.df['TimeStamp (sec)'].mean()-rowdata.df.ix[0,'TimeStamp (sec)'])
avgtime = int(rowdata.df['TimeStamp (sec)'].mean()-rowdata.df.loc[:,'TimeStamp (sec)'].iloc[0])
startdatetime = dateutil.parser.parse("{}, {}".format(row.date,
row.starttime))
@@ -8121,7 +8121,7 @@ def workout_wind_view(request,id=0,message="",successmessage=""):
hascoordinates = 1
try:
latitude = rowdata.df.ix[:,' latitude']
latitude = rowdata.df.loc[:,' latitude']
except KeyError:
hascoordinates = 0
@@ -8129,7 +8129,7 @@ def workout_wind_view(request,id=0,message="",successmessage=""):
hascoordinates = 0
try:
bearing = rowdata.df.ix[:,'bearing'].values
bearing = rowdata.df.loc[:,'bearing'].values
except KeyError:
rowdata.add_bearing()
rowdata.write_csv(f1,gzip=True)
@@ -8811,7 +8811,7 @@ def cumstats(request,theuser=0,
thedict = {}
for field2,verbosename in fielddict.iteritems():
try:
thedict[field2] = cor.ix[field1,field2]
thedict[field2] = cor.loc[field1,field2]
except KeyError:
thedict[field2] = 0
@@ -9030,7 +9030,7 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
thedict = {}
for field2,verbosename in fielddict.iteritems():
try:
thedict[field2] = cor.ix[field1,field2]
thedict[field2] = cor.loc[field1,field2]
except KeyError:
thedict[field2] = 0