0

I am totally new to programming and python and got a problem regarding the naming of a column. I have already tried different approaches but so far without success. For further preparation and visualization of my data I want to name the newly created column which includes the sum of each curreny 'Summe'. How and where do I do that?

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

tweets=pd.read_csv('numTweets.csv', names=['Zeitstempel','Waehrung','AnzahlTweets']) 
tweets1=tweets.groupby('Waehrung').AnzahlTweets.sum()
tweets1.sort_index()[:10]
  • Try df.columns = ['col_name1', 'col_name2']. You can see this answer http://stackoverflow.com/questions/11346283/renaming-columns-in-pandas – Vaishali Apr 06 '17 at 20:33
  • I have already tried that one without success. I have already tried different approaches from the posted answer but I can only rename my first column. Is it possible that this one doesnt work due to the fact that the column I want to name is generated with the sum function? – UmbertoFallo Apr 07 '17 at 09:23
  • You will have to reset_index first. So, tweets1=tweets.groupby('Waehrung').AnzahlTweets.sum().reset_index() and then use columns = [] OR tweets1=tweets.groupby('Waehrung').AnzahlTweets.sum().reset_index(name = 'Summe') – Vaishali Apr 07 '17 at 14:05

0 Answers0