Filtering down a readtable based on specific value in a column
古いコメントを表示
I have a running table of stats from a game with friends and I want to pull only the first place placements into a new table. Essentially, I want to take RawBonusStars(i,:), the entire ith row and place it into BonusStars(i,:). In this dropped row I would have 10 variables, (1 & 3:10) are just numbers or NaN and the 2nd column would be the players name. 

This is what my current code looks like and it returns an error: "Conversion to double from cell is not possible"
stats = 'Mario party tracker.csv'
T = readtable(stats);
games = (unique(T.Game_));
rows = height(T)/4;
RawBonusStars = [T(:,game),(T(:,names)),T(:,placement),T(:,MiniGame),T(:,MaxCoin),T(:,Happening),T(:,Orb),T(:,Shopping),T(:,Running),T(:,RedSpaceStar)];
BonusStars = array2table(zeros(height(games),10));
for i=1:rows
if RawBonusStars.Placement(i) ==1
BonusStars(i,:) = RawBonusStars(i,:)
end
end
I tried to pin point the problem down and I suspect its due to the "name" row. Both RawBonusStars and BonusStars should be initalized as tables so im not sure what the issue is.
6 件のコメント
Sulaymon Eshkabilov
2021 年 7 月 31 日
Can you share your sample data?
Trevor Palmer
2021 年 7 月 31 日
Image Analyst
2021 年 7 月 31 日
編集済み: Image Analyst
2021 年 7 月 31 日
What is RawTable and FilteredTable? They don't show up in your code.
And you don't define your column vectors names, game, placement, etc.
Trevor Palmer
2021 年 7 月 31 日
Cris LaPierre
2021 年 7 月 31 日
What exactly is the issue you are having? There are errors in the code well before the actual assignment operation.
Trevor Palmer
2021 年 7 月 31 日
採用された回答
その他の回答 (2 件)
Image Analyst
2021 年 7 月 31 日
Did you mean this?
RawBonusStars = table(T.Game_, T.Name,T.Placement,T.MinigameCoins, T.Coins,T.HappeningSpaces,T.Orbs,T.ShoppingMoney,T.Running,T.RedSpaces)
2 件のコメント
Cris LaPierre
2021 年 7 月 31 日
Could also be
RawBonusStars = T(:,["Game_","Name","Placement","MinigameCoins","MaxCoins","HappeningSpaces","Orbs","ShoppingMoney","Running","BonusRedStar"]);
but we are guessing what variables were intended to be included
Trevor Palmer
2021 年 7 月 31 日
Cris LaPierre
2021 年 7 月 31 日
編集済み: Cris LaPierre
2021 年 7 月 31 日
Assuming we are missing some of the code (all the column numbers used to construct RawBonusStars, I believe your issue with the actual assignment is a typo.
BonusStars(i,:) = RawBounsStars(i,:)
^^^ % should be RawBonusStars
2 件のコメント
Trevor Palmer
2021 年 7 月 31 日
It looks like you had 62 games, not 61. Use logical indexing to extract all the first place finishers. No loop needed.
stats = 'Mario party tracker.csv'
T = readtable(stats);
RawBonusStars = ["Game_","Name","Placement","BonusMinigameStar","BonusMaxCoin","BonusHappening","BonusOrbStar","BonusShoppingStar","BonusRunnerStar","BonusRedStar"];
ind = T.Placement == 1;
BonusStars = T(ind,RawBonusStars)
カテゴリ
ヘルプ センター および File Exchange で Number games についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
