Convert matrix into value pairs with awk - awk

I have a matrix of data with latitude longitude and temperature on the following format:
15W 14.5W 14W 13.5W 13W
30N 19.3 19.3 19.2 18.9 18.6
30.5N 19.1 19 19 18.9 18.4
31N 18.9 18.8 18.7 18.6 18.3
31.5N 18.9 18.7 18.7 18.6 18.1
32N 18.6 18.5 18.6 18.5 17.5
I would like to use awk to convert it into lines with latitude longitude and temperature.
The output should look like this:
15W 30N 19.3
15W 30.5N 19.1
15W 31N 18.9
15W 31.5N 18.9
15W 32N 18.6
14.5W 30N 19.3
14.5W 30.5N 19
14.5W 31N 18.8
I guess you get the idea. I thought about awk because I have done some other things with it and it was very powerful. But maybe some other tools are to be used here.
The number of rows and columns is not always the same.
I will also need to convert the latitude and longitude to decimal minutes, but I'm taking one step at a time.

awk one-liner (well a bit long maybe):
awk 'NR==1{for(i=1;i<=NF;i++)t[i]=$i}{ r[NR]=$1; for(i=2;i<=NF;i++) v[t[i-1],$1]=$i}END{for(i=1;i<=length(t);i++) for(j=2;j<=NR;j++) print t[i], r[j], v[t[i],r[j]]
} ' file
I would like to format above one-liner into "three-liners" :) :
awk 'NR==1{for(i=1;i<=NF;i++)t[i]=$i}
{ r[NR]=$1; for(i=2;i<=NF;i++) v[t[i-1],$1]=$i}
END{for(i=1;i<=length(t);i++)for(j=2;j<=NR;j++)print t[i], r[j], v[t[i],r[j]]} ' file
test:
kent$ cat t
15W 14.5W 14W 13.5W 13W
30N 19.3 19.3 19.2 18.9 18.6
30.5N 19.1 19 19 18.9 18.4
31N 18.9 18.8 18.7 18.6 18.3
31.5N 18.9 18.7 18.7 18.6 18.1
32N 18.6 18.5 18.6 18.5 17.5
kent$ awk 'NR==1{for(i=1;i<=NF;i++)t[i]=$i}
{ r[NR]=$1; for(i=2;i<=NF;i++) v[t[i-1],$1]=$i}
END{for(i=1;i<=length(t);i++)for(j=2;j<=NR;j++)print t[i], r[j], v[t[i],r[j]]} ' t
15W 30N 19.3
15W 30.5N 19.1
15W 31N 18.9
15W 31.5N 18.9
15W 32N 18.6
14.5W 30N 19.3
14.5W 30.5N 19
14.5W 31N 18.8
14.5W 31.5N 18.7
14.5W 32N 18.5
14W 30N 19.2
14W 30.5N 19
14W 31N 18.7
14W 31.5N 18.7
14W 32N 18.6
13.5W 30N 18.9
13.5W 30.5N 18.9
13.5W 31N 18.6
13.5W 31.5N 18.6
13.5W 32N 18.5
13W 30N 18.6
13W 30.5N 18.4
13W 31N 18.3
13W 31.5N 18.1
13W 32N 17.5

The solution doesn't need to be complicated. It's actually fairly straightforward once you've chosen the right data structure. Simply use GNU awk to employ a true multidimensional array. Run like:
awk -f script.awk file
Contents of script.awk:
NR==1 {
for (i=1;i<=NF;i++) {
a[i]=$i
}
next
}
{
for (j=2;j<=NF;j++) {
b[j-1][NR]["rec"] = a[j-1] FS $1 FS $j
b[j-1][NR]["val"] = $j
}
}
END {
for (x=1;x<=length(b);x++) {
for (y=2;y<=NR;y++) {
if (b[x][y]["val"] != "999.9") {
print b[x][y]["rec"] | "column -t"
}
}
}
}
Results:
15W 30N 19.3
15W 30.5N 19.1
15W 31N 18.9
15W 31.5N 18.9
15W 32N 18.6
14.5W 30N 19.3
14.5W 30.5N 19
14.5W 31N 18.8
14.5W 31.5N 18.7
14.5W 32N 18.5
14W 30N 19.2
14W 30.5N 19
14W 31N 18.7
14W 31.5N 18.7
14W 32N 18.6
13.5W 30N 18.9
13.5W 30.5N 18.9
13.5W 31N 18.6
13.5W 31.5N 18.6
13.5W 32N 18.5
13W 30N 18.6
13W 30.5N 18.4
13W 31N 18.3
13W 31.5N 18.1
13W 32N 17.5
Alternatively, here's the one-liner:
awk 'NR==1 { for (i=1;i<=NF;i++) a[i]=$i; next } { for (j=2;j<=NF;j++) { b[j-1][NR]["rec"] = a[j-1] FS $1 FS $j; b[j-1][NR]["val"] = $j } } END { for (x=1;x<=length(b);x++) for (y=2;y<=NR;y++) if (b[x][y]["val"] != "999.9") print b[x][y]["rec"] | "column -t" }' file

awk 'NR==1{n=split($0,a," ")}NR!=1{for(i=1;i<=n;i++)x[a[i]" "$1]=$(i+1);}END{for(i in x){print i,x[i]}}' temp | sort
tested below:
> cat temp
15W 14.5W 14W 13.5W 13W
30N 19.3 19.3 19.2 18.9 18.6
30.5N 19.1 19 19 18.9 18.4
31N 18.9 18.8 18.7 18.6 18.3
31.5N 18.9 18.7 18.7 18.6 18.1
32N 18.6 18.5 18.6 18.5 17.5
phoenix.250> nawk 'NR==1{n=split($0,a," ")}NR!=1{for(i=1;i<=n;i++)x[a[i]" "$1]=$(i+1);}END{for(i in x){print i,x[i]}}' temp | sort
13.5W 30.5N 18.9
13.5W 30N 18.9
13.5W 31.5N 18.6
13.5W 31N 18.6
13.5W 32N 18.5
13W 30.5N 18.4
13W 30N 18.6
13W 31.5N 18.1
13W 31N 18.3
13W 32N 17.5
14.5W 30.5N 19
14.5W 30N 19.3
14.5W 31.5N 18.7
14.5W 31N 18.8
14.5W 32N 18.5
14W 30.5N 19
14W 30N 19.2
14W 31.5N 18.7
14W 31N 18.7
14W 32N 18.6
15W 30.5N 19.1
15W 30N 19.3
15W 31.5N 18.9
15W 31N 18.9
15W 32N 18.6
>

Related

Vue - After build pages don't load

I've a Vue project buit with vite.
While debbuging the app, everything works ok.
But when i build it to production, and try to open it with preview, the chrome windows hangs loading forever.
Nothing is show on console. Is there anyway to capture the error?
Looks like it's stuck in a forever loop.
Edit
package.json
{
"name": "vue-project",
"version": "0.0.0",
"scripts": {
"dev": "npm run build:icons && vite --host --port 5050",
"build": "npm run build:icons && vue-tsc --noEmit && vite build",
"preview": "vite preview --port 5050",
"typecheck": "vue-tsc --noEmit",
"lint": "eslint src -c .eslintrc.js --fix --rulesdir eslint-internal-rules/ --ext .ts,.js,.vue,.tsx,.jsx",
"build:icons": "tsc -b src/#iconify && node src/#iconify/build-icons.js"
},
"dependencies": {
"#casl/ability": "^6.2.0",
"#casl/vue": "^2.2.0",
"#codemirror/highlight": "^0.19.8",
"#codemirror/lang-html": "^6.1.2",
"#codemirror/lang-javascript": "^6.1.0",
"#codemirror/lang-json": "^6.0.0",
"#codemirror/lint": "^6.0.0",
"#codemirror/theme-one-dark": "^6.1.0",
"#floating-ui/dom": "1.0.0",
"#formkit/auto-animate": "^1.0.0-beta.3",
"#mdi/font": "^7.0.96",
"#vueuse/core": "^8.9.4",
"apexcharts-clevision": "^3.28.5",
"axios": "^0.27.2",
"axios-mock-adapter": "^1.21.2",
"buffer": "^6.0.3",
"chart.js": "^3.9.1",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"pinia": "^2.0.22",
"prismjs": "^1.29.0",
"sass": "^1.54.9",
"unplugin-vue-define-options": "^0.6.2",
"uuid": "^9.0.0",
"vue": "3.2.41",
"vue-chartjs": "^4.1.1",
"vue-codemirror": "^6.1.1",
"vue-flatpickr-component": "^10.0.0",
"vue-i18n": "^9.2.2",
"vue-prism-component": "^2.0.0",
"vue-router": "^4.1.6",
"vue3-apexcharts": "^1.4.1",
"vue3-perfect-scrollbar": "^1.6.0",
"vuetify": "^3.0.0",
"webfontloader": "^1.6.28"
},
"devDependencies": {
"#antfu/eslint-config-vue": "^0.25.2",
"#fullcalendar/core": "^5.11.3",
"#fullcalendar/daygrid": "^5.11.3",
"#fullcalendar/interaction": "^5.11.3",
"#fullcalendar/list": "^5.11.3",
"#fullcalendar/timegrid": "^5.11.3",
"#fullcalendar/vue3": "^5.11.2",
"#iconify-json/mdi": "^1.1.33",
"#iconify/tools": "^2.1.0",
"#iconify/vue": "^3.2.1",
"#intlify/vite-plugin-vue-i18n": "^5.0.1",
"#types/lodash": "^4.14.186",
"#types/node": "^18.7.18",
"#types/uuid": "^8.3.4",
"#types/webfontloader": "^1.6.34",
"#typescript-eslint/eslint-plugin": "^5.38.0",
"#typescript-eslint/parser": "^5.38.0",
"#vitejs/plugin-vue": "^3.1.0",
"#vitejs/plugin-vue-jsx": "^2.0.1",
"eslint": "^8.23.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-promise": "^6.0.1",
"eslint-plugin-sonarjs": "^0.14.0",
"eslint-plugin-vue": "^9.5.1",
"postcss-html": "^1.5.0",
"stylelint": "^14.12.0",
"stylelint-config-idiomatic-order": "^8.1.0",
"stylelint-config-standard-scss": "^5.0.0",
"stylelint-use-logical-spec": "^4.1.0",
"type-fest": "^2.19.0",
"typescript": "^4.8.3",
"unplugin-auto-import": "^0.10.3",
"unplugin-vue-components": "^0.21.2",
"vite": "^3.2.2",
"vite-plugin-pages": "^0.27.1",
"vite-plugin-vue-layouts": "^0.7.0",
"vite-plugin-vuetify": "1.0.0",
"vue-tsc": "^1.0.9"
},
"packageManager": "yarn#1.22.18",
"resolutions": {
"postcss": "8",
"stylelint-order": "5",
"postcss-sorting": "^7.0.1"
}
}
output of build
╭─ ♥ 22:14 |  E:            code
╰─ npm run build
> vue-project#0.0.0 build
> npm run build:icons && vue-tsc --noEmit && vite build
> vue-project#0.0.0 build:icons
> tsc -b src/#iconify && node src/#iconify/build-icons.js
Bundled icons from E:\_Development\_repos\hiperstream\hiperstreamCloudPlatform\cloud-platform\code\node_modules\#iconify-json\mdi\icons.json
Saved src/#iconify/icons-bundle.js (2848016 bytes)
vite v3.2.2 building for production...
transforming (253) node_modules\vuetify\lib\composables\ssrBoot.mjs[plugin:vite:esbuild] Duplicate key "key" in object literal
50 | ? _withDirectives((_openBlock(), _createBlock(_resolveDynamicComponent(_unref(config).app.enableI18n ? 'i18n-t' : 'span'), _mergeProps({
51 | key: 0,
52 | key: "badge",
| ^
53 | class: ["nav-item-badge", __props.item.badgeClass]
54 | }, _unref(dynamicI18nProps)(__props.item.badgeContent, 'span')), {
✓ 1193 modules transformed.
dist/assets/avatar-1.aac046b6.png 15.96 KiB
dist/assets/avatar-2.0ae005f8.png 22.59 KiB
dist/assets/pose-f-28.a182fba0.png 9.21 KiB
dist/assets/pose-f-3.a3617bf1.png 8.31 KiB
dist/assets/mac-pc.4e376c3f.png 140.24 KiB
dist/assets/pose-f-39.43496c42.png 6.65 KiB
dist/assets/pose-m-14.a95cbb6a.png 5.87 KiB
dist/assets/pose-m-5.d7160542.png 6.80 KiB
dist/assets/pose-m-34.cb61966e.png 7.35 KiB
dist/assets/avatar-3.3ef9169b.png 11.57 KiB
dist/assets/avatar-4.406ee6ab.png 20.73 KiB
dist/assets/avatar-5.bad78850.png 18.35 KiB
dist/assets/avatar-6.3bc22d4b.png 18.22 KiB
dist/assets/avatar-7.8807e18e.png 18.07 KiB
dist/assets/avatar-8.942ae414.png 16.39 KiB
dist/assets/auth-v2-login-illustration-bordered-dark.1621a082.png 67.92 KiB
dist/assets/auth-v2-login-illustration-bordered-light.5efb7928.png 64.49 KiB
dist/assets/auth-v2-login-illustration-dark.c163247b.png 67.13 KiB
dist/assets/auth-v2-login-illustration-light.c910569c.png 68.40 KiB
dist/assets/paypal.8c1354c3.svg 2.24 KiB
dist/assets/illustration-1.20d12d31.png 12.84 KiB
dist/assets/illustration-2.042b082c.png 11.76 KiB
dist/assets/pose-fs-9.c6abbba4.png 28.74 KiB
dist/assets/sitting-girl-with-laptop-dark.aa688fe5.png 9.07 KiB
dist/assets/sitting-girl-with-laptop-light.bd520dbb.png 9.82 KiB
dist/assets/card-meetup.c5ffac4a.png 195.24 KiB
dist/assets/html5.ff3e7cf8.png 4.78 KiB
dist/assets/python.1d56c267.png 4.16 KiB
dist/assets/react.52bd27c0.png 5.31 KiB
dist/assets/vue.33fa8801.png 4.07 KiB
dist/assets/xamarin.d2086975.png 4.08 KiB
dist/assets/chrome.391a2294.png 7.47 KiB
dist/assets/american-express.2c04e485.png 8.14 KiB
dist/assets/knowledge-base-bg-dark.9e1eb36c.png 29.65 KiB
dist/assets/pricing-tree-1.61561baa.png 4.86 KiB
dist/assets/pricing-tree-3.7c67f762.png 5.59 KiB
dist/index.html 1.07 KiB
dist/assets/useGenerateImageVariant.ec010ed6.js 0.58 KiB / gzip: 0.27 KiB
dist/assets/VCard.b6709399.js 9.07 KiB / gzip: 2.06 KiB
dist/assets/VAlert.c1a0a22c.js 5.83 KiB / gzip: 1.70 KiB
dist/assets/webfontloader.b777d690.js 19.47 KiB / gzip: 5.78 KiB
dist/assets/VForm.45e996af.js 1.47 KiB / gzip: 0.61 KiB
dist/assets/VCheckbox.e52cedcf.js 1.67 KiB / gzip: 0.64 KiB
dist/assets/login.e1da9684.js 23.87 KiB / gzip: 8.25 KiB
dist/assets/blank.c23886c7.js 0.36 KiB / gzip: 0.24 KiB
dist/assets/VWindow.74c52ec5.js 9.08 KiB / gzip: 2.56 KiB
dist/assets/VWindowItem.f856cfbe.js 3.54 KiB / gzip: 1.11 KiB
dist/assets/VTabs.dffdacbb.js 20.22 KiB / gzip: 4.81 KiB
dist/assets/VTable.d527e358.js 1.56 KiB / gzip: 0.62 KiB
dist/assets/AppPricing.63e41703.js 14.20 KiB / gzip: 6.06 KiB
dist/assets/useInvoiceStore.3f404cbb.js 0.75 KiB / gzip: 0.36 KiB
dist/assets/sitting-girl-with-laptop-light.2ab0b492.js 0.25 KiB / gzip: 0.14 KiB
dist/assets/useLayoutsStore.7257820e.js 1.61 KiB / gzip: 0.62 KiB
dist/assets/VContainer.cf5a234e.js 0.52 KiB / gzip: 0.30 KiB
dist/assets/VTimelineItem.c57c8a72.js 7.16 KiB / gzip: 1.81 KiB
dist/assets/vue.runtime.esm-bundler.e5a66098.js 5.45 KiB / gzip: 1.89 KiB
dist/assets/index.21f4736b.js 42.20 KiB / gzip: 7.63 KiB
dist/assets/VTextarea.51d5864e.js 9.17 KiB / gzip: 2.56 KiB
dist/assets/_id_.30711c66.js 31.52 KiB / gzip: 4.48 KiB
dist/assets/index.aac33ec4.js 0.89 KiB / gzip: 0.46 KiB
dist/assets/index.9ba56bbe.js 28.73 KiB / gzip: 4.65 KiB
dist/assets/DefaultTabCrudLayout.vue_vue_type_script_setup_true_lang.c9f21d22.js 2.76 KiB / gzip: 0.97 KiB
dist/assets/DefaultCrudTabCardAccordionContentLayout.vue_vue_type_script_setup_true_lang.4411eb1b.js 5.70 KiB / gzip: 1.18 KiB
dist/assets/index.93a7da00.js 0.91 KiB / gzip: 0.47 KiB
dist/assets/VExpansionPanel.a3e74888.js 8.09 KiB / gzip: 2.00 KiB
dist/assets/pricing.3cf2db40.js 17.59 KiB / gzip: 2.80 KiB
dist/assets/Layout.vue_vue_type_script_setup_true_lang.59dd5321.js 39.91 KiB / gzip: 7.26 KiB
dist/assets/DefaultCrudTabCardAccordionContentLayout.a1cdd194.js 0.42 KiB / gzip: 0.23 KiB
dist/assets/faq.76ac9c5f.js 12.59 KiB / gzip: 2.88 KiB
dist/assets/DefaultCrudTabContentVCardLayout.ee966228.js 1.09 KiB / gzip: 0.51 KiB
dist/assets/DefaultVCardLayout.vue_vue_type_script_setup_true_lang.c0c59562.js 2.17 KiB / gzip: 0.78 KiB
dist/assets/DefaultLayoutWithHorizontalNav.fd6f082f.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/DefaultLayoutWithVerticalNav.e139d247.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/DefaultTabCrudLayout.df749d43.js 0.31 KiB / gzip: 0.18 KiB
dist/assets/NavBarI18n.8a521c1b.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/DefaultVCardLayout.dfa4f164.js 0.31 KiB / gzip: 0.17 KiB
dist/assets/NavBarNotifications.d9e7daac.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/NavbarThemeSwitcher.c87d20bf.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/UserProfile.8b5cee81.js 0.12 KiB / gzip: 0.10 KiB
dist/assets/login.21c684c6.css 0.62 KiB / gzip: 0.26 KiB
dist/assets/VCardCrudTabContentLayout.abe161c0.js 1.66 KiB / gzip: 0.63 KiB
dist/assets/VAlert.12d954e1.css 4.68 KiB / gzip: 1.17 KiB
dist/assets/VCard.782c479c.css 6.74 KiB / gzip: 1.52 KiB
dist/assets/blank.21020790.css 0.06 KiB / gzip: 0.07 KiB
dist/assets/VCheckbox.de0921d5.css 0.13 KiB / gzip: 0.12 KiB
dist/assets/_tab_.960e3200.css 0.43 KiB / gzip: 0.24 KiB
dist/assets/VTabs.a70cd9cf.css 3.04 KiB / gzip: 0.82 KiB
dist/assets/VWindow.1bd1bd93.css 2.15 KiB / gzip: 0.51 KiB
dist/assets/EnableOneTimePasswordDialog.a42d412e.css 2.25 KiB / gzip: 0.63 KiB
dist/assets/AppPricing.61deeeed.css 0.06 KiB / gzip: 0.07 KiB
dist/assets/index.6b7aa9ad.css 0.46 KiB / gzip: 0.17 KiB
dist/assets/crm.95f00275.css 0.51 KiB / gzip: 0.31 KiB
dist/assets/VTable.4c8b70a0.css 5.63 KiB / gzip: 0.86 KiB
dist/assets/_id_.43495c33.css 0.43 KiB / gzip: 0.23 KiB
dist/assets/VTextarea.5dc8269a.css 1.36 KiB / gzip: 0.46 KiB
dist/assets/VTimelineItem.07999e79.css 16.35 KiB / gzip: 1.70 KiB
dist/assets/VExpansionPanel.da2668ed.css 6.40 KiB / gzip: 1.21 KiB
dist/assets/pricing.56987cf6.css 0.43 KiB / gzip: 0.25 KiB
dist/assets/faq.c2655a3e.css 0.37 KiB / gzip: 0.23 KiB
dist/assets/_id_.85426b33.css 0.53 KiB / gzip: 0.28 KiB
dist/assets/AppDateTimePicker.2e517c19.css 24.49 KiB / gzip: 3.87 KiB
dist/assets/_tab_.85a982d6.js 114.32 KiB / gzip: 17.83 KiB
dist/assets/EnableOneTimePasswordDialog.vue_vue_type_script_setup_true_lang.e28f045b.js 54.21 KiB / gzip: 26.72 KiB
dist/assets/AppDateTimePicker.vue_vue_type_style_index_0_lang.7a89fa00.js 102.95 KiB / gzip: 22.96 KiB
dist/assets/_id_.0d3c91dd.js 131.99 KiB / gzip: 24.15 KiB
dist/assets/index.60024895.css 440.04 KiB / gzip: 56.52 KiB
dist/assets/crm.b882faf7.js 723.03 KiB / gzip: 157.73 KiB
dist/assets/index.fc5e085d.js 4054.75 KiB / gzip: 978.41 KiB
output of preview
╰─ npm run preview
> vue-project#0.0.0 preview
> vite preview --port 5050
➜ Local: http://127.0.0.1:5050/
➜ Network: use --host to expose
The page on browser after build and preview
You can't serve your vue build with live Server
This question is already Answered here How to run production site after build vue cli
The problem was happening because, as I expected, the application was in a infinite loop.
The application firstly was using dynamic routes created using vite-plugin-pages
This was generating some problems during build, then I manually wrote the routes. Unfortunally I did forget to add the basic permissions to vue #casl
meta: {action:'read', subject:'Auth'},

Vue Transition not working when attempting to toggle between svgs. Working with vue transitions

Simple as the title suggests, I'm not sure why the transition is not working to toggle between both svgs.
What am I missing here? I wrapped the svgs in divs, but that didn't help at all.
Any advise would be greatly appreciated.
Cheers!
CodePen:
https://codepen.io/LovelyAndy/pen/MWmyzmm
Html
<div id="icon">
<transition name="fade" mode="out-in"><div v-if="show"
#click="show = !show">
<svg width="41" height="58" viewBox="0 0 41 58" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="0.5" width="40" height="40" rx="20" fill="#F9F9FF"/>
<path d="M14.9916 56.146C14.8796 56.2393 14.6696 56.3653 14.3616 56.524C14.0629 56.6827 13.6943 56.8227 13.2556 56.944C12.8169 57.0653 12.3316 57.1213 11.7996 57.112C10.9876 57.0933 10.2596 56.9487 9.61559 56.678C8.98093 56.398 8.43959 56.02 7.99159 55.544C7.55293 55.068 7.21693 54.522 6.98359 53.906C6.75026 53.29 6.63359 52.632 6.63359 51.932C6.63359 50.8867 6.84359 49.9627 7.26359 49.16C7.68359 48.3573 8.26693 47.7273 9.01359 47.27C9.76959 46.8127 10.6469 46.584 11.6456 46.584C12.3363 46.584 12.9476 46.6773 13.4796 46.864C14.0116 47.0507 14.4456 47.2513 14.7816 47.466L13.9836 49.384C13.7503 49.2067 13.4376 49.0247 13.0456 48.838C12.6629 48.642 12.2196 48.544 11.7156 48.544C11.1929 48.544 10.7029 48.6887 10.2456 48.978C9.79759 49.2673 9.43359 49.6593 9.15359 50.154C8.88293 50.6393 8.74759 51.1947 8.74759 51.82C8.74759 52.4827 8.87359 53.066 9.12559 53.57C9.37759 54.0647 9.73693 54.452 10.2036 54.732C10.6703 55.012 11.2163 55.152 11.8416 55.152C12.3923 55.152 12.8636 55.0633 13.2556 54.886C13.6476 54.7087 13.9463 54.522 14.1516 54.326L14.9916 56.146ZM19.2793 57.168C18.71 57.168 18.192 57.056 17.7253 56.832C17.268 56.5987 16.904 56.244 16.6333 55.768C16.3626 55.292 16.2273 54.6853 16.2273 53.948C16.2273 53.2573 16.3673 52.66 16.6473 52.156C16.9273 51.652 17.296 51.2647 17.7533 50.994C18.2106 50.714 18.696 50.574 19.2093 50.574C19.816 50.574 20.2733 50.672 20.5813 50.868C20.8986 51.064 21.1506 51.2787 21.3373 51.512L21.4633 50.882H23.2833V57H21.3233V56.244C21.23 56.3373 21.09 56.4587 20.9033 56.608C20.726 56.7573 20.502 56.888 20.2313 57C19.9606 57.112 19.6433 57.168 19.2793 57.168ZM19.8393 55.572C20.5206 55.572 21.0153 55.264 21.3233 54.648V53.15C21.2113 52.8513 21.0153 52.6133 20.7353 52.436C20.4646 52.2587 20.1426 52.17 19.7693 52.17C19.3493 52.17 18.9853 52.3287 18.6773 52.646C18.3693 52.954 18.2153 53.3553 18.2153 53.85C18.2153 54.1767 18.29 54.4707 18.4393 54.732C18.5886 54.9933 18.7846 55.1987 19.0273 55.348C19.2793 55.4973 19.55 55.572 19.8393 55.572ZM27.2909 57.126C26.7869 57.126 26.3156 57.0373 25.8769 56.86C25.4476 56.6827 25.0836 56.4353 24.7849 56.118L25.5969 55.04C25.8956 55.3107 26.1709 55.5067 26.4229 55.628C26.6843 55.74 26.9176 55.796 27.1229 55.796C27.3656 55.796 27.5663 55.7587 27.7249 55.684C27.8836 55.6093 27.9629 55.488 27.9629 55.32C27.9629 55.1613 27.8976 55.0353 27.7669 54.942C27.6456 54.8487 27.4869 54.774 27.2909 54.718C27.0949 54.6527 26.8849 54.5873 26.6609 54.522C26.1009 54.3447 25.6949 54.088 25.4429 53.752C25.2003 53.4067 25.0789 53.0333 25.0789 52.632C25.0789 52.324 25.1583 52.016 25.3169 51.708C25.4849 51.3907 25.7463 51.1293 26.1009 50.924C26.4649 50.7093 26.9316 50.602 27.5009 50.602C28.0143 50.602 28.4483 50.6533 28.8029 50.756C29.1576 50.8587 29.4936 51.0267 29.8109 51.26L29.0689 52.408C28.8916 52.268 28.6909 52.1513 28.4669 52.058C28.2523 51.9553 28.0516 51.8993 27.8649 51.89C27.6129 51.8807 27.4169 51.9273 27.2769 52.03C27.1369 52.1233 27.0669 52.2353 27.0669 52.366C27.0576 52.5433 27.1229 52.6833 27.2629 52.786C27.4123 52.8887 27.5989 52.968 27.8229 53.024C28.0469 53.08 28.2663 53.1453 28.4809 53.22C28.9196 53.3693 29.2696 53.584 29.5309 53.864C29.7923 54.1347 29.9229 54.4987 29.9229 54.956C29.9229 55.3293 29.8249 55.684 29.6289 56.02C29.4423 56.3467 29.1529 56.6127 28.7609 56.818C28.3783 57.0233 27.8883 57.126 27.2909 57.126ZM32.1386 48.194H34.0986V50.854H35.5826V52.38H34.0986V57H32.1386V52.38H31.1866V50.854H32.1386V48.194Z" fill="#1A0050"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.6 17.9C16.2627 17.9 16.8 17.3627 16.8 16.7C16.8 16.0373 16.2627 15.5 15.6 15.5C14.9373 15.5 14.4 16.0373 14.4 16.7C14.4 17.3627 14.9373 17.9 15.6 17.9ZM15.6 20.3C17.5882 20.3 19.2 18.6882 19.2 16.7C19.2 14.7118 17.5882 13.1 15.6 13.1C13.6118 13.1 12 14.7118 12 16.7C12 18.6882 13.6118 20.3 15.6 20.3Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M15.66 21.2C14.6659 21.2 13.86 22.0059 13.86 23L13.86 24.8C13.86 25.4628 13.3227 26 12.6599 26C11.9972 26 11.46 25.4628 11.46 24.8L11.46 23C11.46 20.6804 13.3404 18.8 15.66 18.8C17.9796 18.8 19.86 20.6804 19.86 23V23.6C19.86 24.2628 19.3227 24.8 18.66 24.8C17.9972 24.8 17.46 24.2628 17.46 23.6V23C17.46 22.0059 16.6541 21.2 15.66 21.2Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M26.3998 17.9C25.737 17.9 25.1998 17.3627 25.1998 16.7C25.1998 16.0373 25.737 15.5 26.3998 15.5C27.0624 15.5 27.5998 16.0373 27.5998 16.7C27.5998 17.3627 27.0624 17.9 26.3998 17.9ZM26.3998 20.3C24.4115 20.3 22.7998 18.6882 22.7998 16.7C22.7998 14.7118 24.4115 13.1 26.3998 13.1C28.388 13.1 29.9998 14.7118 29.9998 16.7C29.9998 18.6882 28.388 20.3 26.3998 20.3Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M26.3396 21.2C27.3337 21.2 28.1396 22.0059 28.1396 23V24.8C28.1396 25.4628 28.6769 26 29.3396 26C30.0024 26 30.5396 25.4628 30.5396 24.8V23C30.5396 20.6804 28.6592 18.8 26.3396 18.8C24.02 18.8 22.1396 20.6804 22.1396 23V23.6C22.1396 24.2628 22.6769 24.8 23.3396 24.8C24.0024 24.8 24.5396 24.2628 24.5396 23.6V23C24.5396 22.0059 25.3456 21.2 26.3396 21.2Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M21.0604 24.5C20.0663 24.5 19.2604 25.3059 19.2604 26.3L19.2604 28.1C19.2604 28.7628 18.7231 29.3 18.0603 29.3C17.3976 29.3 16.8604 28.7628 16.8604 28.1L16.8604 26.3C16.8604 23.9804 18.7408 22.1 21.0604 22.1C23.38 22.1 25.2604 23.9804 25.2604 26.3V28.1C25.2604 28.7628 24.7232 29.3 24.0604 29.3C23.3977 29.3 22.8604 28.7628 22.8604 28.1V26.3C22.8604 25.3059 22.0545 24.5 21.0604 24.5Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M21.0004 21.2C21.6632 21.2 22.2004 20.6628 22.2004 20C22.2004 19.3373 21.6632 18.8 21.0004 18.8C20.3377 18.8 19.8004 19.3373 19.8004 20C19.8004 20.6628 20.3377 21.2 21.0004 21.2ZM21.0004 23.6C22.9887 23.6 24.6004 21.9883 24.6004 20C24.6004 18.0118 22.9887 16.4 21.0004 16.4C19.0122 16.4 17.4004 18.0118 17.4004 20C17.4004 21.9883 19.0122 23.6 21.0004 23.6Z" fill="#712EFF"/>
</svg>
</div> <div v-else
#click="show = !show" >
<svg width="24" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.6 9.9C7.26274 9.9 7.8 9.36274 7.8 8.7C7.8 8.03726 7.26274 7.5 6.6 7.5C5.93726 7.5 5.4 8.03726 5.4 8.7C5.4 9.36274 5.93726 9.9 6.6 9.9ZM6.6 12.3C8.58822 12.3 10.2 10.6882 10.2 8.7C10.2 6.71178 8.58822 5.1 6.6 5.1C4.61178 5.1 3 6.71178 3 8.7C3 10.6882 4.61178 12.3 6.6 12.3Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.66002 13.2C5.66588 13.2 4.85997 14.0059 4.85997 15L4.85996 16.8C4.85996 17.4628 4.3227 18 3.65995 18C2.99721 18 2.45996 17.4628 2.45996 16.8L2.45997 15C2.45998 12.6804 4.34041 10.8 6.66002 10.8C8.9796 10.8 10.86 12.6804 10.86 15V15.6C10.86 16.2628 10.3227 16.8 9.65998 16.8C8.99725 16.8 8.45998 16.2628 8.45998 15.6V15C8.45998 14.0059 7.65411 13.2 6.66002 13.2Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.4003 9.9C16.7375 9.9 16.2003 9.36274 16.2003 8.7C16.2003 8.03726 16.7375 7.5 17.4003 7.5C18.0629 7.5 18.6003 8.03726 18.6003 8.7C18.6003 9.36274 18.0629 9.9 17.4003 9.9ZM17.4003 12.3C15.412 12.3 13.8003 10.6882 13.8003 8.7C13.8003 6.71178 15.412 5.1 17.4003 5.1C19.3885 5.1 21.0003 6.71178 21.0003 8.7C21.0003 10.6882 19.3885 12.3 17.4003 12.3Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.3401 13.2C18.3342 13.2 19.1401 14.0059 19.1401 15V16.8C19.1401 17.4628 19.6774 18 20.3401 18C21.0029 18 21.5401 17.4628 21.5401 16.8V15C21.5401 12.6804 19.6597 10.8 17.3401 10.8C15.0205 10.8 13.1401 12.6804 13.1401 15V15.6C13.1401 16.2628 13.6774 16.8 14.3401 16.8C15.0029 16.8 15.5401 16.2628 15.5401 15.6V15C15.5401 14.0059 16.3461 13.2 17.3401 13.2Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.0599 16.5C11.0658 16.5 10.2599 17.3059 10.2599 18.3L10.2599 20.1C10.2599 20.7628 9.7226 21.3 9.05985 21.3C8.39712 21.3 7.85986 20.7628 7.85986 20.1L7.85988 18.3C7.85989 15.9804 9.74031 14.1 12.0599 14.1C14.3795 14.1 16.2599 15.9804 16.2599 18.3V20.1C16.2599 20.7628 15.7227 21.3 15.0599 21.3C14.3972 21.3 13.8599 20.7628 13.8599 20.1V18.3C13.8599 17.3059 13.054 16.5 12.0599 16.5Z" fill="#712EFF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.9999 13.2C12.6627 13.2 13.1999 12.6628 13.1999 12C13.1999 11.3373 12.6627 10.8 11.9999 10.8C11.3372 10.8 10.7999 11.3373 10.7999 12C10.7999 12.6628 11.3372 13.2 11.9999 13.2ZM11.9999 15.6C13.9882 15.6 15.5999 13.9883 15.5999 12C15.5999 10.0118 13.9882 8.4 11.9999 8.4C10.0117 8.4 8.3999 10.0118 8.3999 12C8.3999 13.9883 10.0117 15.6 11.9999 15.6Z" fill="#712EFF"/>
</svg>
</div>
</transition>
</div>
CSS
body {
align-items: center;
background-color: white;
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
}
.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}
.fade-enter, .fade-leave-to {
opacity: 0
}
You are missing a key.
When toggling between elements that have the same tag name, you must tell Vue that they are distinct elements by giving them unique key attributes. Otherwise, Vue’s compiler will only replace the content of the element for efficiency. Even when technically unnecessary though, it’s considered good practice to always key multiple items within a component.
Enter/Leave & List Transitions
Example:
<script>
export default {
data() {
return {
show: false,
}
},
}
</script>
body {
align-items: center;
background-color: white;
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
}
.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}
.fade-enter, .fade-leave-to {
opacity: 0
}
<div id="icon">
<transition name="fade" mode="out-in">
<div v-if="show" key="one" #click="show = !show">
svg...
</div>
<div v-else key="two" #click="show = !show">
svg...
</div>
</transition>
</div>

missing observation panel data, bring forward value 20 periods

Here's to read in a DataFrame like the one I'm looking at
pd.DataFrame({
'period' : [1, 2, 3, 4, 5, 8, 9, 10, 11, 13, 14, 15, 16, 19, 20, 21, 22,
23, 25, 26],
'id' : [1285, 1285, 1285, 1285, 1285, 1285, 1285, 1285, 1285, 1285, 1285,
1285, 1285, 1285, 1285, 1285, 1285, 1285, 1285, 1285],
'pred': [-1.6534775, -1.6534775, -1.6534775, -1.6534775, -1.6534775,
-1.6534775, -1.6534775, -1.6534775, -1.6534775, -1.6534775,
-1.6534775, -1.6534775, -1.6534775, -1.6534775, -1.6534775,
-1.6534775, -1.6534775, -1.6534775, -1.6534775, -1.6534775],
'ret' : [ None, -0.02222222, -0.01363636, 0. , -0.02764977,
None, -0.00909091, -0.01376147, 0.00465116, None,
0.01869159, 0. , 0. , None , -0.00460829,
0.00462963, 0.02304147, 0. , None, -0.00050756]})
Which will look like this when read in.
period id pred ret
0 1 1285 -1.653477 NaN
1 2 1285 -1.653477 -0.022222
2 3 1285 -1.653477 -0.013636
3 4 1285 -1.653477 0.000000
4 5 1285 -1.653477 -0.027650
5 8 1285 -1.653477 NaN
6 9 1285 -1.653477 -0.009091
7 10 1285 -1.653477 -0.013761
8 11 1285 -1.653477 0.004651
9 13 1285 -1.653477 NaN
10 14 1285 -1.653477 0.018692
11 15 1285 -1.653477 0.000000
12 16 1285 -1.653477 0.000000
13 19 1285 -1.653477 NaN
14 20 1285 -1.653477 -0.004608
15 21 1285 -1.653477 0.004630
16 22 1285 -1.653477 0.023041
17 23 1285 -1.653477 0.000000
18 25 1285 -1.653477 NaN
19 26 1285 -1.653477 -0.000508
pred is 20 period prediction and consequently I want to do is bring the returns back 20 days. (but do it in a flexible way.)
Here's the lag function I have presently
def lag(df, col, lag_dist=1, ref='period', group='id'):
df = df.copy()
new_col = 'lag'+str(lag_dist)+'_'+col
df[new_col] = df.groupby(group)[col].shift(lag_dist)
# set NaN values that differ from specified
df[new_col] = (df.groupby(group)[ref]
.shift(lag_dist)
.sub(df[ref])
.eq(-lag_dist)
.mul(1)
.replace(0,np.nan)*df[new_col])
return df[new_col]
but when I run
df['fut20_ret'] = lag(df, 'ret', -20, 'period')
df.head(20)
I get
period id pred gain fee prc ret fut20_ret
0 1 1285 -1.653478 0.000000 0.87 1.000000 NaN NaN
1 2 1285 -1.653478 -0.022222 0.87 0.977778 -0.022222 NaN
2 3 1285 -1.653478 -0.035556 0.87 0.964444 -0.013636 NaN
3 4 1285 -1.653478 -0.035556 0.87 0.964444 0.000000 NaN
4 5 1285 -1.653478 -0.062222 0.87 0.937778 -0.027650 NaN
6 8 1285 -1.653478 -0.022222 0.87 0.977778 NaN NaN
7 9 1285 -1.653478 -0.031111 0.87 0.968889 -0.009091 NaN
8 10 1285 -1.653478 -0.044444 0.87 0.955556 -0.013761 NaN
9 11 1285 -1.653478 -0.040000 0.87 0.960000 0.004651 NaN
10 13 1285 -1.653478 -0.048889 0.87 0.951111 NaN NaN
11 14 1285 -1.653478 -0.031111 0.87 0.968889 0.018692 NaN
12 15 1285 -1.653478 -0.031111 0.87 0.968889 0.000000 NaN
13 16 1285 -1.653478 -0.031111 0.87 0.968889 0.000000 NaN
15 19 1285 -1.653478 -0.035556 0.87 0.964444 NaN NaN
16 20 1285 -1.653478 -0.040000 0.87 0.960000 -0.004608 NaN
17 21 1285 -1.653478 -0.035556 0.87 0.964444 0.004630 NaN
18 22 1285 -1.653478 -0.013333 0.87 0.986667 0.023041 NaN
19 23 1285 -1.653478 -0.013333 0.87 0.986667 0.000000 NaN
How can I modify my lag function so that it works properly? It's close but I'm struggling on the last little bit.

SQL query is not working (Error in rsqlite_send_query)

This is what the head of my data frame looks like
> head(d19_1)
SMZ SIZ1_diff SIZ1_base SIZ2_diff SIZ2_base SIZ3_diff SIZ3_base SIZ4_diff SIZ4_base SIZ5_diff SIZ5_base
1 1 -620 4170 -189 1347 -35 2040 82 1437 244 1533
2 2 -219 831 -57 255 -4 392 8 282 14 297
3 3 -426 834 -162 294 -134 379 -81 241 -22 221
4 4 -481 676 -142 216 -114 267 -50 158 -43 166
5 5 -233 1711 -109 584 54 913 71 624 74 707
6 6 -322 1539 -79 512 -50 799 23 532 63 576
Total_og Total_base %_SIZ1 %_SIZ2 %_SIZ3 %_SIZ4 %_SIZ5 Total_og Total_base
1 11980 12648 14.86811 14.03118 1.715686 5.706333 15.916504 11980 12648
2 2156 2415 26.35379 22.35294 1.020408 2.836879 4.713805 2156 2415
3 1367 2314 51.07914 55.10204 35.356201 33.609959 9.954751 1367 2314
4 790 1736 71.15385 65.74074 42.696629 31.645570 25.903614 790 1736
5 5339 5496 13.61777 18.66438 5.914567 11.378205 10.466761 5339 5496
6 4362 4747 20.92268 15.42969 6.257822 4.323308 10.937500 4362 4747
The datatype of the data frame is as below str(d19_1)
> str(d19_1)
'data.frame': 1588 obs. of 20 variables:
$ SMZ : int 1 2 3 4 5 6 7 8 9 10 ...
$ SIZ1_diff : int -620 -219 -426 -481 -233 -322 -176 -112 -34 -103 ...
$ SIZ1_base : int 4170 831 834 676 1711 1539 720 1396 998 1392 ...
$ SIZ2_diff : int -189 -57 -162 -142 -109 -79 -12 72 -36 -33 ...
$ SIZ2_base : int 1347 255 294 216 584 512 196 437 343 479 ...
$ SIZ3_diff : int -35 -4 -134 -114 54 -50 16 4 26 83 ...
$ SIZ3_base : int 2040 392 379 267 913 799 361 804 566 725 ...
$ SIZ4_diff : int 82 8 -81 -50 71 23 36 127 46 75 ...
$ SIZ4_base : int 1437 282 241 158 624 532 242 471 363 509 ...
$ SIZ5_diff : int 244 14 -22 -43 74 63 11 143 79 125 ...
$ SIZ5_base : int 1533 297 221 166 707 576 263 582 429 536 ...
$ Total_og : int 11980 2156 1367 790 5339 4362 2027 4715 3465 4561 ...
$ Total_base: int 12648 2415 2314 1736 5496 4747 2168 4464 3278 4375 ...
$ %_SIZ1 : num 14.9 26.4 51.1 71.2 13.6 ...
$ %_SIZ2 : num 14 22.4 55.1 65.7 18.7 ...
$ %_SIZ3 : num 1.72 1.02 35.36 42.7 5.91 ...
$ %_SIZ4 : num 5.71 2.84 33.61 31.65 11.38 ...
$ %_SIZ5 : num 15.92 4.71 9.95 25.9 10.47 ...
$ Total_og : int 11980 2156 1367 790 5339 4362 2027 4715 3465 4561 ...
$ Total_base: int 12648 2415 2314 1736 5496 4747 2168 4464 3278 4375 ...
When I run the below query, it is returning me the below error and I don't know why. I don't have any column in table
Query
d20_1 <- sqldf('SELECT *, CASE
WHEN SMZ BETWEEN 1 AND 110 THEN "Baltimore City"
WHEN SMZ BETWEEN 111 AND 217 THEN "Anne Arundel County"
WHEN SMZ BETWEEN 218 AND 405 THEN "Baltimore County"
WHEN SMZ BETWEEN 406 AND 453 THEN "Carroll County"
WHEN SMZ BETWEEN 454 AND 524 THEN "Harford County"
WHEN SMZ BETWEEN 1667 AND 1674 THEN "York County"
ELSE 0
END Jurisdiction
FROM d19_1')
Error:
Error in rsqlite_send_query(conn#ptr, statement) :
table d19_1 has no column named <NA>
Your code works correctly for me:
d19_1 <- structure(list(SMZ = 1:6, SIZ1_diff = c(-620L, -219L, -426L,
-481L, -233L, -322L), SIZ1_base = c(4170L, 831L, 834L, 676L,
1711L, 1539L), SIZ2_diff = c(-189L, -57L, -162L, -142L, -109L,
-79L), SIZ2_base = c(1347L, 255L, 294L, 216L, 584L, 512L), SIZ3_diff = c(-35L,
-4L, -134L, -114L, 54L, -50L), SIZ3_base = c(2040L, 392L, 379L,
267L, 913L, 799L), SIZ4_diff = c(82L, 8L, -81L, -50L, 71L, 23L
), SIZ4_base = c(1437L, 282L, 241L, 158L, 624L, 532L), SIZ5_diff = c(244L,
14L, -22L, -43L, 74L, 63L), SIZ5_base = c(1533L, 297L, 221L,
166L, 707L, 576L), Total_og = c(11980L, 2156L, 1367L, 790L, 5339L,
4362L), Total_base = c(12648L, 2415L, 2314L, 1736L, 5496L, 4747L
), X._SIZ1 = c(14.86811, 26.35379, 51.07914, 71.15385, 13.61777,
20.92268), X._SIZ2 = c(14.03118, 22.35294, 55.10204, 65.74074,
18.66438, 15.42969), X._SIZ3 = c(1.715686, 1.020408, 35.356201,
42.696629, 5.914567, 6.257822), X._SIZ4 = c(5.706333, 2.836879,
33.609959, 31.64557, 11.378205, 4.323308), X._SIZ5 = c(15.916504,
4.713805, 9.954751, 25.903614, 10.466761, 10.9375), Total_og.1 = c(11980L,
2156L, 1367L, 790L, 5339L, 4362L), Total_base.1 = c(12648L, 2415L,
2314L, 1736L, 5496L, 4747L)), .Names = c("SMZ", "SIZ1_diff",
"SIZ1_base", "SIZ2_diff", "SIZ2_base", "SIZ3_diff", "SIZ3_base",
"SIZ4_diff", "SIZ4_base", "SIZ5_diff", "SIZ5_base", "Total_og",
"Total_base", "X._SIZ1", "X._SIZ2", "X._SIZ3", "X._SIZ4", "X._SIZ5",
"Total_og.1", "Total_base.1"), row.names = c(NA, -6L), class = "data.frame")
library(sqldf)
sqldf('SELECT *, CASE
WHEN SMZ BETWEEN 1 AND 110 THEN "Baltimore City"
WHEN SMZ BETWEEN 111 AND 217 THEN "Anne Arundel County"
WHEN SMZ BETWEEN 218 AND 405 THEN "Baltimore County"
WHEN SMZ BETWEEN 406 AND 453 THEN "Carroll County"
WHEN SMZ BETWEEN 454 AND 524 THEN "Harford County"
WHEN SMZ BETWEEN 1667 AND 1674 THEN "York County"
ELSE 0
END Jurisdiction
FROM d19_1')

Use AWK on multi FASTA file to add new column based on contig header

I have a multi FASTA file that needs to be parsed so Glimmer multi-extract script can process it. It is composed of many contigs each with it's own header that starts with ">". What I need is to add each header as a new column, the problem is I don't know very much about the linux bash or awk for that matter.
>contig-7
orf00002 1741 461
orf00003 3381 1747
>Wcontig-7000023
>Wcontig-11112
orf00001 426 2648
orf00002 2710 4581
orf00003 4569 5480
orf00004 6990 6133
orf00006 9180 7108
orf00007 10201 9209
orf00008 11663 10203
orf00009 12489 11680
orf00010 13153 12473
orf00011 14382 13225
orf00013 14715 15968
orf00014 19868 16410
>Wcontig-1674000002
orf00001 2995 637
orf00002 2497 1166
orf00003 2984 2529
I need to have each contig header added as a first column along with a tab delimiter.
>contig-7
>contig-7 orf00002 1741 461
>contig-7 orf00003 3381 1747
>Wcontig-7000023
>Wcontig-11112
>Wcontig-11112 orf00001 426 2648
>Wcontig-11112 orf00002 2710 4581
>Wcontig-11112 orf00003 4569 5480
>Wcontig-11112 orf00004 6990 6133
>Wcontig-11112 orf00006 9180 7108
>Wcontig-11112 orf00007 10201 9209
>Wcontig-11112 orf00008 11663 10203
>Wcontig-11112 orf00009 12489 11680
>Wcontig-11112 orf00010 13153 12473
>Wcontig-11112 orf00011 14382 13225
>Wcontig-11112 orf00013 14715 15968
>Wcontig-11112 orf00014 19868 16410
>Wcontig-1674000002
>Wcontig-1674000002 orf00001 2995 637
>Wcontig-1674000002 orf00002 2497 1166
>Wcontig-1674000002 orf00003 2984 2529
Also, after adding the new column I have to erase all the headers, so it would end up looking like this
>contig-7 orf00002 1741 461
>contig-7 orf00003 3381 1747
>Wcontig-11112 orf00001 426 2648
>Wcontig-11112 orf00002 2710 4581
>Wcontig-11112 orf00003 4569 5480
>Wcontig-11112 orf00004 6990 6133
>Wcontig-11112 orf00006 9180 7108
>Wcontig-11112 orf00007 10201 9209
>Wcontig-11112 orf00008 11663 10203
>Wcontig-11112 orf00009 12489 11680
>Wcontig-11112 orf00010 13153 12473
>Wcontig-11112 orf00011 14382 13225
>Wcontig-11112 orf00013 14715 15968
>Wcontig-11112 orf00014 19868 16410
>Wcontig-1674000002 orf00001 2995 637
>Wcontig-1674000002 orf00002 2497 1166
>Wcontig-1674000002 orf00003 2984 2529
Awk can be really handy to solve this problem:
awk '{if($1 ~ /contig/){c=$1}else{print c"\t"$0}}' <yourfile>