无法将csv数据加载到散景中

问题描述 投票:1回答:2

我无法将数据从csv文件加载到散景中,它可以从散景数据库中运行,但是当我从csv文件尝试它没有加载时,所以我一直在阅读但到目前为止没有运气。提前致谢

df = pd.read_csv('unemployment1948.csv', delimiter = ',', index_col = 
                 'Year')
df = pd.DataFrame(df)
df.head()


output_notebook()
group = df[35:].groupby('Year')
source = ColumnDataSource(df)
group.describe()
df.columns
#source = ColumnDataSource(df(x=df.loc[15:40].index, 
#                              y=df.loc[15:40].Annual))

p = figure(plot_height=300, plot_width=900, x_range=group, 
           title='Umployment over the years',
           x_axis_label='Year', y_axis_label='Annual')

p.circle(x=index, y='Annual', width=0.9, color ='#35B778' , source=source)
show(p)
python-3.x csv plot bokeh
2个回答
0
投票

你的df已经是大熊猫DataFrame。试试这个:

import os
import pandas as pd
from bokeh.io import show
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure

df = pd.read_csv(os.path.join(os.path.dirname(__file__), "unemployment1948.csv",))
output_notebook()
source = ColumnDataSource(df)

p = figure(plot_height = 300, plot_width = 900,
           title = 'Umployment over the years',
           x_axis_label = 'Year', y_axis_label = 'Annual')

p.circle(x = 'Year', y = 'Annual', line_width = 0.9, color = '#35B778' , source = source)
show(p)

enter image description here


0
投票

我学会了如何处理Data Frame和ColumnDataSource,因此您可以轻松地操作数据,而不需要使用OS模块。谢谢您的帮助。

import csv
#import re
import pandas as pd
import numpy as np
#import random
##from collections import Counter, defaultdict
#import random

dfU = pd.read_csv('unemployment1948.csv')
dfU = pd.DataFrame(dfU)
dfU.index
y = dfU.iloc[35:].Year
x = dfU.iloc[35:].Annual
#xRange = dfU.iloc[35:]
source = ColumnDataSource(dfU)

output_notebook()
p = figure(plot_height=300, plot_width=800, title='Unemployment over the years')
p.vbar(x='Year', top='Annual', width=0.9, color ='#35B778' , source=source)
show(p)
© www.soinside.com 2019 - 2024. All rights reserved.