我有以下代码。
rushingyards = 0
passingyards = 0
templist = []
combineddf = play.groupby(['GameCode','PlayType']).sum()
combineddf.to_csv('data/combined.csv', sep=',')
combineddff =pd.DataFrame.from_csv('data/combined.csv')
temp = {}
for row in combineddff.itertuples():
if row[1] in ('RUSH', 'PASS'):
temp['GameCode'] = row[0]
if row[1] == 'RUSH':
temp['Rushingyards'] = row[10]
else:
temp['PassingYards'] = row[10]
else:
continue
templist.append(temp)
我合并的csv的负责人在下面。
PlayType PlayNumber PeriodNumber Clock OffenseTeamCode \
GameCode
2047220131026 ATTEMPT 779 19 2220 1896
2047220131026 FIELD_GOAL 351 9 1057 946
2047220131026 KICKOFF 1244 32 4388 3316
2047220131026 PASS 8200 204 6549 14730
2047220131026 PENALTY 1148 29 1481 2372
DefenseTeamCode OffensePoints DefensePoints Down Distance \
GameCode
2047220131026 1896 142 123 NaN NaN
2047220131026 476 52 51 12 17
2047220131026 2846 231 195 NaN NaN
2047220131026 23190 1131 1405 147 720
2047220131026 2842 188 198 19 84
Spot DriveNumber DrivePlay
GameCode
2047220131026 24 NaN NaN
2047220131026 19 49 3
2047220131026 850 NaN NaN
2047220131026 3719 1161 80
2047220131026 514 164 1
我必须检查playtype是否为Rush或pass,并相应地创建如下列表。
Gamecode rushing_yards passingyards
299004720130829 893 401
299004720130824 450 657
299004720130821 430 357
我无法正确附加值。 Evey运行的时间,它给出了游戏代码,rushing_yards和passyards的所有类似值。请帮助。
答案 0 :(得分:0)
这是因为您要附加对象private async Task TakePhoto()
{
_mediaCapture.VideoDeviceController.FlashControl.Auto = false;
_mediaCapture.VideoDeviceController.FlashControl.Enabled = ((CameraViewModel) this.DataContext).FlashEnable;
if (_mediaCapture.VideoDeviceController.FocusControl.Supported)
{
await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync();
}
if (_mediaCapture.VideoDeviceController.TorchControl.Supported)
{
_mediaCapture.VideoDeviceController.TorchControl.Enabled = true;
}
ImageEncodingProperties imageEncodingProperties = ImageEncodingProperties.CreateJpeg();
Guid guid = Guid.NewGuid();
StorageFile cardStorageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("cardStorageFile" + guid.ToString() + ".jpg", CreationCollisionOption.ReplaceExisting);
using (var imageStream = new InMemoryRandomAccessStream())
{
await _mediaCapture.CapturePhotoToStreamAsync(imageEncodingProperties, imageStream);
BitmapDecoder dec = await BitmapDecoder.CreateAsync(imageStream);
BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(imageStream, dec);
enc.BitmapTransform.Rotation = BitmapRotation.Clockwise90Degrees;
await enc.FlushAsync();
using (var fileStream = await cardStorageFile.OpenStreamForWriteAsync())
{
try
{
await RandomAccessStream.CopyAsync(imageStream, fileStream.AsOutputStream());
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
using (var randomAccessStream = await cardStorageFile.OpenAsync(FileAccessMode.ReadWrite))
{
if (((CameraViewModel) this.DataContext).CardBitmapImage == null)
{
VideoEncodingProperties photoSizeEncodingProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.Photo) as VideoEncodingProperties;
if (photoSizeEncodingProperties != null)
{
((CameraViewModel) this.DataContext).CardBitmapImage = new WriteableBitmap((int) photoSizeEncodingProperties.Width, (int) photoSizeEncodingProperties.Height);
}
}
await ((CameraViewModel)this.DataContext).CardBitmapImage.SetSourceAsync(randomAccessStream);
}
((CameraViewModel) this.DataContext).StorageFileImage = cardStorageFile;
((CameraViewModel)this.DataContext).CaptureEnable = false;
((CameraViewModel)this.DataContext).IsBusy = false;
}
的引用。您基本上只是存储对同一对象的引用,这导致所有这些值的值相同。将你的临时字典放在for循环中,你应该看到这个问题的解决方案,因为它在循环中的每次迭代时实例化一个新的dict对象。