Public
Edited
Feb 17, 2023
Insert cell
Insert cell
# 一、行业涨跌
Insert cell
xlsx='http://localhost:8000/申万行业指数行情序列2000-20221231.xlsx'
Insert cell
csvFile='http://localhost:8000/申万行业指数行情序列2000-20221231.csv'
Insert cell
Insert cell
csvData=FileAttachment("申万行业指数行情序列2000-20221231.csv").csv()
Insert cell
Insert cell
df2=dfd.readExcel(xlsx)
Insert cell
df=dfd.readCSV(csvFile)
Insert cell
Insert cell
pd=P.py`import pandas as pd
pd`
Insert cell
Insert cell
df3.head().toString()
Insert cell
toArray(df3.T)
Insert cell
P.py`o=list(${df3['时间']}.unique())
o`
Insert cell
P.py`s=list(${df3}.shape)
s`
Insert cell
Inputs.table(data)
Insert cell
toArray(df3.set_index('时间').stack().reset_index())
Insert cell
##### read by d3
Insert cell
data=d3.csv('http://localhost:8000/申万行业指数行情序列2000-20221231.csv',{typed:false})
Insert cell
Insert cell
Insert cell
data3={
const data=df3.set_index('时间').stack().reset_index()
data.columns=['时间','key','value']
data['value']=data['value'].str.replace(",",'').astype('float')
return toArray(data)
}

Insert cell
Insert cell
data2={
const columns={}
Object.keys(data[0]).forEach(k=>columns[k]=[])
const result =data.map(d=>{
Object.keys(d).forEach(k=>columns[k].push(d[k]))
})
return columns
}
Insert cell
aqdf=aq.loadCSV(csvFile)
Insert cell
aqTable=aqdf.fold(aq.range(1,31))
Insert cell
aqData=aqTable.objects().map((d,i)=>{
return {
时间:d.时间,
key:d.key,
value:+String(d.value).replace(",",''),
}
})
Insert cell
plt=Plot.plot({
x:{ticks:20,tickLabel:'test'},
marks:[Plot.line(data3,{x:'时间',y:'value',stroke:'key'})],
})
Insert cell
Plot.plot({
marks:[
Plot.line(aqdf,{x:aqdf.columnAt(0).data,y:aqdf.columnAt(2).data.map(d=>+d.replace(",",''))})
]
})
Insert cell
Plot.plot({
marks:[
Plot.line(aqData,{x:'时间',y:'value',stroke:'key'})
],
color:{legend:true}
})
Insert cell
s=new d3.InternSet([4,5,6])
Insert cell
s.forEach((k)=>console.log(k))
Insert cell
import {Py,pyodide} from "@cottonsh/pyodide"
Insert cell
import {loadFile,toArray} from "@cottonsh/utils"
Insert cell
P=new Py()
Insert cell
dfd = require("danfojs@1.0.5/lib/bundle.js").catch(() => {
window.dfd.Series.prototype.print = window.dfd.DataFrame.prototype.print =function(df){
return print(df)
};
// };
return window.dfd;
})
Insert cell
申万行业指数行情序列2000-20221231.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more