Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14215

Unable to fetch the data using column name from pandas dataframe after assigning a column name

$
0
0

I have created a pandas dataframe from an API endpoint. I have used the following to convert to a df.

df = pd.json_normalize(js.loads(js.dumps(key_value))

This however does create df as required but the column names are the reference ids. I have extracted the column of interest by:

new_df = df.iloc[:,4]

Now since at a later stage I would need to merge the above df with another df I assigned a column name to the above df and I have done that using:

new_df.columns = ["EMP_ID"]

However, when I use

print(new_df['EMP_ID']

I get None.

I did figure out that pandas is unable to recognise the column name. Is there a different way to assign a column name in this scenario.

Note: When merging this df with another will give a KeyError issue as column name ["EMP_ID"] is not recognised.


Viewing all articles
Browse latest Browse all 14215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>