我很难读取excel表pd.read_excel().
我的excel表在它的原始形式中看起来像这样:
我希望数据框看起来像这样:
bar baz foo
one two one two one two
A B C D E F
baz one 0.085930 -0.848468 0.911572 -0.705026 -1.284458 -0.602760
two 0.385054 2.539314 0.589164 0.765126 0.210199 -0.481789
three -0.352475 -0.975200 -0.403591 0.975707 0.533924 -0.195430
Run Code Online (Sandbox Code Playgroud)
这有可能吗?
我失败的尝试:
xls_file = pd.read_excel(data_file, header=[0,1,2], index_col=None)
Run Code Online (Sandbox Code Playgroud)
链接到原始excel文件:
https://www.dropbox.com/s/ek646ab4yb1fvdq/ipsos_excel_tables_type_2_trimed_nosig.xlsx?dl=0
Run Code Online (Sandbox Code Playgroud) 我创建了一个 Choropleth 地图,我想知道是否可以为每个州添加一个下拉列表。当您选择下拉菜单时,图表会变为在该州随时间推移获得的学士学位数量的折线图。
我的数据示例:
year state statetotal ba_total
0 1984.0 AK 221.0 108.0
1 1985.0 AK 242.0 141.0
2 1984.0 NC 229.0 117.0
3 1985.0 NC 257.0 138.0
4 1984.0 MA 272.0 165.0
5 1985.0 MA 280.0 176.0
6 1984.0 NY 375.0 249.0
7 1985.0 NY 309.0 208.0
Run Code Online (Sandbox Code Playgroud)
这是我迄今为止尝试过的:
for col in df.columns:
df[col] = df[col].astype(str)
scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\
[0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']]
df['text'] = df['statename'] + '<br>' + \
'Bachelor '+df['ba_total']+'<br>'+ \
'Master '+df['ma_total']+'<br>'+ \
'PhD …Run Code Online (Sandbox Code Playgroud) 我正在重新创建示例等值区并试图添加一个滑块,当拖动时,它会逐年变化.另一位用户提出了类似的问题,但他们没有收到回复.我做了一些搜索并找到了一个示例,其中用户为其他年份生成了随机值并创建了一个滑块,但它是在JavaScript中,我不知道如何将其转换为Python.
这是JavaScript中的代码:
Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv', function(err, rows){
function unpack(rows, key) {
return rows.map(function(row) { return row[key]; });
}
var randomize = z => z.map(d => Math.pow(Math.random(), 2) * 30000);
var data = unpack(rows, 'total exports');
var frames = [{
data: [{z: unpack(rows, 'total exports')}],
traces: [0],
name: '1990',
layout: {title: '1990 US Agriculture Exports by State'}
}, {
data: [{z: randomize(data)}],
traces: [0],
name: '1995',
layout: {title: '1995 US Agriculture Exports by State'}
}, {
data: …Run Code Online (Sandbox Code Playgroud) 我正在尝试重新创建以下报告第 4 页上的条形图:
该人物有三个条形,前两个堆叠在一起,第三个则躲在旁边。我见过这个问题的迭代,但没有一个以这种精确的方式重新创建这个数字。
这是数据:
a <- rep(c('RHB', 'FERS', 'CSRS'), 3)
b <- c(rep('Assets', 3), rep('Amount Past Due', 3),
rep('Actuarial Liability', 3))
c <- c(45.0, 122.5, 152.3, 47.2, 3.4, 4.8, 114.4, 143.4, 181.3)
df <- data.frame(a,b,c)
names(df) <- c('Fund', 'Condition', 'Value')
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经做到了:
p <- ggplot(subset_data, aes(fill=Condition, y=Value, x=Fund)) +
geom_bar(position="stack", stat="identity") +
coord_flip()
Run Code Online (Sandbox Code Playgroud)
我并不偏爱,ggplot所以如果有另一个工具效果更好,我可以使用另一个包。
choropleth ×2
plotly ×2
python ×2
dataframe ×1
excel ×1
ggplot2 ×1
javascript ×1
multi-index ×1
pandas ×1
r ×1