Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 491

Pandas - Attempting to Rearrange Row in Dataframe, but get Error

$
0
0

I'am trying to rearrange a row in the dataframe for the indexed row "Germany", but i get error " TypeError : 'method' object does not support item assignment " , code is below,

import pandas as pdimport numpy as np combined_global_fx_currencies = r'x:\xxx\xxx\xxxxx\xxxxx\xxxxxx.xlsx'global_fx = pd.read_excel(combined_global_fx_currencies)global_fx['Country'] = ['United States', 'China', 'Euro Zone', 'Japan', 'United Kingdom', 'Australia', 'New Zealand', 'Russia', 'Saudi Arabia', 'Brazil', 'Mexico', 'Canada', 'Switzerlanter']global_fx = global_fx.set_index('Country')## Multiplying by 100, cause by default in pandas its not putting in Percetange Terms like it is on the Excel Filedglobal_fx['3 Years']= global_fx['3 Years'] * 100global_fx['1 Year']= global_fx['1 Year'] * 100global_fx['YTD']= global_fx['YTD'] * 100global_fx['1 Month']= global_fx['1 Month'] * 100global_fx['1 Week']= global_fx['1 Week'] * 100 global_fx['Daily']= global_fx['Daily'] * 100## Add Row for Germany and equated to same values for the Euro Zone which is the Eur/USDglobal_fx.loc['Germany'] = global_fx.loc['Euro Zone']global_fx = global_fx.reset_indexglobal_fx['Country'] = ['United States', 'China', 'Euro Zone', 'Germany', 'Japan', 'United Kingdom', 'Australia', 'New Zealand', 'Russia', 'Saudi Arabia', 'Brazil', 'Mexico', 'Canada', 'Switzerland']global_fx = global_fx.set_index('Country')print(global_fx)Error :  global_fx['Country'] = ['United States', 'China', 'Euro Zone', 'Germany', 'Japan', 'United Kingdom', 'Australia', 'New Zealand', 'Russia', 'Saudi Arabia', 'Brazil', 'Mexico', 'Canada', 'Switzerland'] TypeError: 'method' object does not support item assignment

Viewing all articles
Browse latest Browse all 491

Trending Articles



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