How to access a row from a panda dataframe using index without column header?
up vote
0
down vote
favorite
e.g -
df= A B C
1 2 3
2 4 5
2 1 3
I want to access second row without header
If I do df.iloc[[1]]
it is giving me -
A B C
2 4 5
as output, but I want
2 4 5
as output. No column header is needed and eventually I will store that in list.
python pandas dataframe
|
show 1 more comment
up vote
0
down vote
favorite
e.g -
df= A B C
1 2 3
2 4 5
2 1 3
I want to access second row without header
If I do df.iloc[[1]]
it is giving me -
A B C
2 4 5
as output, but I want
2 4 5
as output. No column header is needed and eventually I will store that in list.
python pandas dataframe
1
df.iloc[1].values
– Alex
23 hours ago
I will store that in list.
- Do you think values2, 4 ,5
? Likedf.iloc[1].tolist()
?
– jezrael
23 hours ago
Or is necessary save DataFrame with no header to csv likedf.iloc[[1]].to_csv(file, header=None, index=False)
?
– jezrael
23 hours ago
I will take 2,4,5 and eventually store in a list..which will be looked like ['2','4','5']
– Sayantan
23 hours ago
hmmm, so need join it by space like' '.join(df.iloc[1].tolist())
?
– jezrael
23 hours ago
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
e.g -
df= A B C
1 2 3
2 4 5
2 1 3
I want to access second row without header
If I do df.iloc[[1]]
it is giving me -
A B C
2 4 5
as output, but I want
2 4 5
as output. No column header is needed and eventually I will store that in list.
python pandas dataframe
e.g -
df= A B C
1 2 3
2 4 5
2 1 3
I want to access second row without header
If I do df.iloc[[1]]
it is giving me -
A B C
2 4 5
as output, but I want
2 4 5
as output. No column header is needed and eventually I will store that in list.
python pandas dataframe
python pandas dataframe
edited 21 hours ago
halfer
14.1k757104
14.1k757104
asked 23 hours ago
Sayantan
243
243
1
df.iloc[1].values
– Alex
23 hours ago
I will store that in list.
- Do you think values2, 4 ,5
? Likedf.iloc[1].tolist()
?
– jezrael
23 hours ago
Or is necessary save DataFrame with no header to csv likedf.iloc[[1]].to_csv(file, header=None, index=False)
?
– jezrael
23 hours ago
I will take 2,4,5 and eventually store in a list..which will be looked like ['2','4','5']
– Sayantan
23 hours ago
hmmm, so need join it by space like' '.join(df.iloc[1].tolist())
?
– jezrael
23 hours ago
|
show 1 more comment
1
df.iloc[1].values
– Alex
23 hours ago
I will store that in list.
- Do you think values2, 4 ,5
? Likedf.iloc[1].tolist()
?
– jezrael
23 hours ago
Or is necessary save DataFrame with no header to csv likedf.iloc[[1]].to_csv(file, header=None, index=False)
?
– jezrael
23 hours ago
I will take 2,4,5 and eventually store in a list..which will be looked like ['2','4','5']
– Sayantan
23 hours ago
hmmm, so need join it by space like' '.join(df.iloc[1].tolist())
?
– jezrael
23 hours ago
1
1
df.iloc[1].values
– Alex
23 hours ago
df.iloc[1].values
– Alex
23 hours ago
I will store that in list.
- Do you think values 2, 4 ,5
? Like df.iloc[1].tolist()
?– jezrael
23 hours ago
I will store that in list.
- Do you think values 2, 4 ,5
? Like df.iloc[1].tolist()
?– jezrael
23 hours ago
Or is necessary save DataFrame with no header to csv like
df.iloc[[1]].to_csv(file, header=None, index=False)
?– jezrael
23 hours ago
Or is necessary save DataFrame with no header to csv like
df.iloc[[1]].to_csv(file, header=None, index=False)
?– jezrael
23 hours ago
I will take 2,4,5 and eventually store in a list..which will be looked like ['2','4','5']
– Sayantan
23 hours ago
I will take 2,4,5 and eventually store in a list..which will be looked like ['2','4','5']
– Sayantan
23 hours ago
hmmm, so need join it by space like
' '.join(df.iloc[1].tolist())
?– jezrael
23 hours ago
hmmm, so need join it by space like
' '.join(df.iloc[1].tolist())
?– jezrael
23 hours ago
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
0
down vote
use list_ob = list(df.iloc[1])
and use list_ob, it will return desired output.
add a comment |
up vote
0
down vote
try this below snippets to get different types of results as you wish,
print df.iloc[1].values #<type 'numpy.ndarray'> [2 4 5]
print df.iloc[1].values.tolist() #<type 'list'> [2, 4, 5]
print ' '.join(map(str,df.iloc[1].values.tolist())) #<type 'str'> 2 4 5
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
use list_ob = list(df.iloc[1])
and use list_ob, it will return desired output.
add a comment |
up vote
0
down vote
use list_ob = list(df.iloc[1])
and use list_ob, it will return desired output.
add a comment |
up vote
0
down vote
up vote
0
down vote
use list_ob = list(df.iloc[1])
and use list_ob, it will return desired output.
use list_ob = list(df.iloc[1])
and use list_ob, it will return desired output.
answered 23 hours ago
Nikhil Mangire
629
629
add a comment |
add a comment |
up vote
0
down vote
try this below snippets to get different types of results as you wish,
print df.iloc[1].values #<type 'numpy.ndarray'> [2 4 5]
print df.iloc[1].values.tolist() #<type 'list'> [2, 4, 5]
print ' '.join(map(str,df.iloc[1].values.tolist())) #<type 'str'> 2 4 5
add a comment |
up vote
0
down vote
try this below snippets to get different types of results as you wish,
print df.iloc[1].values #<type 'numpy.ndarray'> [2 4 5]
print df.iloc[1].values.tolist() #<type 'list'> [2, 4, 5]
print ' '.join(map(str,df.iloc[1].values.tolist())) #<type 'str'> 2 4 5
add a comment |
up vote
0
down vote
up vote
0
down vote
try this below snippets to get different types of results as you wish,
print df.iloc[1].values #<type 'numpy.ndarray'> [2 4 5]
print df.iloc[1].values.tolist() #<type 'list'> [2, 4, 5]
print ' '.join(map(str,df.iloc[1].values.tolist())) #<type 'str'> 2 4 5
try this below snippets to get different types of results as you wish,
print df.iloc[1].values #<type 'numpy.ndarray'> [2 4 5]
print df.iloc[1].values.tolist() #<type 'list'> [2, 4, 5]
print ' '.join(map(str,df.iloc[1].values.tolist())) #<type 'str'> 2 4 5
answered 21 hours ago
Mohamed Thasin ah
2,94331234
2,94331234
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53220899%2fhow-to-access-a-row-from-a-panda-dataframe-using-index-without-column-header%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
df.iloc[1].values
– Alex
23 hours ago
I will store that in list.
- Do you think values2, 4 ,5
? Likedf.iloc[1].tolist()
?– jezrael
23 hours ago
Or is necessary save DataFrame with no header to csv like
df.iloc[[1]].to_csv(file, header=None, index=False)
?– jezrael
23 hours ago
I will take 2,4,5 and eventually store in a list..which will be looked like ['2','4','5']
– Sayantan
23 hours ago
hmmm, so need join it by space like
' '.join(df.iloc[1].tolist())
?– jezrael
23 hours ago