我能够生成这个df
if word in newStopWords1d:
print 'found'
哪个工作正常。我补充说:
downloads url_info_hostname date Size
0 9829 url1.com 2018-03-01 1.0
1 1285651465 url2.com 2018-03-01 868789.0
2 1079238 url3.com 2018-03-01 17121.0
3 77305525 url4.com 2018-03-01 23464.0
问题是当我导出csv当然我错过了上面的打印输出。
当我尝试将其添加为数据帧的一部分时,它将下载的所有内容转换为科学记数法。 我试着这样做:
print ("Daily sum of downloads: %s" % (sum(df1['downloads'])))
print ("Total data (GB) transferred %s" % (sum(df1['Size'])))
每件事都有NaN。
我的数据框看起来像这样:
df1.loc['Daily sum of downloads'] = pd.Series(df1[‘downloads'].sum(), index = [‘downloads’])
df1.loc['Total data (GB) transferred'] = pd.Series(df1['Size'].sum(), index = [‘downloads’])
答案 0 :(得分:1)
您可以使用loc添加名为sum的行并格式化列
df.loc['sum', ['downloads', 'Size']] = df.sum()
df['downloads'] = df['downloads'].apply(lambda x: '{:.0f}'.format(x))
downloads url_info_hostname date Size
0 9829 url1.com 2018-03-01 1.0
1 1285651465 url2.com 2018-03-01 868789.0
2 1079238 url3.com 2018-03-01 17121.0
3 77305525 url4.com 2018-03-01 23464.0
sum 1364046057 NaN NaN 909375.0