kslo39
kslo39

Reputation: 63

Python - getting 0 in all rows in the first column of the dataframe

input :

     status = [] 
     status.append(User)
     print(CsvUser)
     final_CsvUser= pd.DataFrame([CsvUser],index=None)`

output of final_CsvUser:

    externalId  userName    emails        phoneNumbers    title     familyName  

0        1         1      [email protected]     111-111-1111   Analyst      Ben 

0        2         2      [email protected]  222-222-2222   Analyst      notBen

output of print(CsvUser):

{'externalId': 1, 'userName': 1, 'emails': '[email protected]', 'phoneNumbers': '111-111-111', 
'title': 'Analyst', 'familyName': 'Ben'},{'externalId': 2, 'userName': 2,
 'emails': '[email protected]', 'phoneNumbers': '222-222-2222', 'title': 'Analyst',
 'familyName': 'notBen'}

I am converting this obj CsvUser to a dataframe and unexpectedly getting 0 to all the rows in the first column.

Upvotes: 0

Views: 713

Answers (1)

Chetan Prabhu
Chetan Prabhu

Reputation: 600

The first column defaults to an index. Reset it to one of your existing columns.

import pandas as pd
df = pd.DataFrame(csv_user)
df.set_index('externalId', inplace=True)
df

Upvotes: 3

Related Questions