Python table gives NaN when initialized with series

0 votes

IF I am using this code:

a=array([2,2,2,3])
c=DataFrame({"A":1,
"B":Series(a),
"C":Timestamp("20130203"),
"D":array([3]*4),
"E":"Elephant"},index=["Firstyear","Secondyear","Thirdyear","Fourthyear"])
print(c)

I am getting the following output

A B C D E
Firstyear 1 NaN 2013-02-03 3 Elephant
Secondyear 1 NaN 2013-02-03 3 Elephant
Thirdyear 1 NaN 2013-02-03 3 Elephant
Fourthyear 1 NaN 2013-02-03 3 Elephant

But why is the B table giving Nan output and not the "a" array?

Jul 9, 2019 in Python by Gani
1,301 views

1 answer to this question.

0 votes

The NaN value you are getting is because you are trying to print both keys and values at a time for the series ---> a, this is turning out to be Nan :

I have done modification in the code ,this is generating the output as required :

import numpy as np

import pandas as pd

a=np.array([2,2,2,3],dtype="int")

data= ({"A":1,

"B":pd.Series(a).values,

"C":pd.Timestamp("20130203"),

"D":np.array([3]*4),

"E":"Elephant"})

df = pd.DataFrame(data, index=["Firstyear","Secondyear","Thirdyear","Fourthyear"]) 

print (df)

image

answered Jul 9, 2019 by Yogi

Related Questions In Python

0 votes
1 answer

Inconsistent Whitespace error occurrence when using Python doctest with newline characters

Hi. It's pretty simple actually. All you ...READ MORE

answered Feb 12, 2019 in Python by Nymeria
• 3,560 points
2,807 views
0 votes
1 answer

Error:UnicodeDecodeError when reading CSV file in Pandas with Python

Hello @kartik, Try this: import pandas as pd df = ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,840 points
7,852 views
0 votes
1 answer
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,125 views
+1 vote
2 answers

Measuring the distance between pixels on OpenCv with Python

You can try this: Mat pts1(nPts, 1, CV_8UC2), ...READ MORE

answered Aug 24, 2018 in Python by Omkar
• 69,220 points
10,574 views
+1 vote
1 answer

How to replace id with attribute corresponding to id of another table?

Use the following query statement and let ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 58,020 points
2,502 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP