pandas in matlab using iloc for indexing

조회 수: 9 (최근 30일)
Amir Azadeh Ranjbar
Amir Azadeh Ranjbar 2023년 10월 4일
답변: Mike Croucher 2024년 5월 29일
i want use pandas in matlab but i cant use this for iloc indexing :
% Import pandas:
pd = py.importlib.import_module('pandas');
% Create a dataframe:
df = pd.read_csv('movies.csv');
df.head(int8(5))
df.shape
df.dtypes
df.iloc(int8(5)) % in this line i got some error ->
"Same base class matlab.mixin.internal.indexing.Paren specified more"+...
"than once for class py.pandas.core.indexing._iLocIndexer. Specify"+...
"each base class only once."
  댓글 수: 1
Aimee Nogoy
Aimee Nogoy 2024년 5월 28일
Did you ever figure this out? Got a similar error but for a different module

댓글을 달려면 로그인하십시오.

답변 (1개)

Mike Croucher
Mike Croucher 2024년 5월 29일
Indexing into Pandas data frames in this way is not supported. As of R2024a, you can convert the dataframe to a MATLAB table and then index into that
%Make a pandas dataframe
last_names = py.pandas.Series({"Sanchez","Johnson","Zhang","Diaz","Brown"},dtype="object");
age = py.numpy.random.randint(18,high=85,size=py.len(last_names));
height = py.numpy.random.randint(60,high=78,size=py.len(last_names));
df = py.pandas.DataFrame(struct("LastName",last_names,"Age",age,"Height",height));
%Convert to table
md = table(df)
md =
5×3 table
LastName Age Height
_________ ___ ______
"Sanchez" 45 75
"Johnson" 29 64
"Zhang" 65 71
"Diaz" 26 76
"Brown" 23 71
%Index into it
md(1,:)
ans =
1×3 table
LastName Age Height
_________ ___ ______
"Sanchez" 45 75

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by