Fixing joining two datasets with same variables - join

I want to join two datasets.
Datasets had same columns/ variables.
Dataset 1 (n11)
caseid v000 v005 age v021 v022 v023 v024 resi region v102 education pregnant v445 v501 v717 wealth stra occupation
1 101 15 2 NP6 342191 5 101 10 1 1 2 1 2 1 0 2190 1 4 4 NPIR61FL$ssubreg=1, NPIR61FL$v025=2 2
2 101 19 2 NP6 342191 7 101 10 1 1 2 1 2 0 0 2300 1 4 3 NPIR61FL$ssubreg=1, NPIR61FL$v025=2 2
3 101 19 4 NP6 342191 2 101 10 1 1 2 1 2 1 0 2139 1 4 3 NPIR61FL$ssubreg=1, NPIR61FL$v025=2 2
4 101 21 4 NP6 342191 5 101 10 1 1 2 1 2 0 0 1855 1 4 2 NPIR61FL$ssubreg=1, NPIR61FL$v025=2 2
5 101 45 3 NP6 342191 5 101 10 1 1 2 1 2 0 0 2133 3 4 3 NPIR61FL$ssubreg=1, NPIR61FL$v025=2 2
6 101 47 2 NP6 342191 1 101 10 1 1 2 1 2 2 0 2022 1 4 4 NPIR61FL$ssubreg=1, NPIR61FL$v025=2 2
Dataset 2 (n16)
caseid v000 v005 age v021 v022 v023 v024 resi region v102 education pregnant v445 v501 v717 wealth stra occupation
1 101 2 2 NP5 295061 6 101 1 1 1 2 1 2 0 0 2534 1 4 2 NPIR51FL$v024=1, NPIR51FL$v025=2 2
2 101 2 3 NP5 295061 1 101 1 1 1 2 1 2 2 0 2061 0 4 2 NPIR51FL$v024=1, NPIR51FL$v025=2 2
3 101 3 3 NP5 295061 1 101 1 1 1 2 1 2 2 0 2157 1 4 1 NPIR51FL$v024=1, NPIR51FL$v025=2 2
4 101 4 1 NP5 295061 4 101 1 1 1 2 1 2 0 0 2370 1 4 1 NPIR51FL$v024=1, NPIR51FL$v025=2 2
5 101 6 6 NP5 295061 2 101 1 1 1 2 1 2 3 0 2254 0 4 2 NPIR51FL$v024=1, NPIR51FL$v025=2 2
6 101 7 2 NP5 295061 2 101 1 1 1 2 1 2 2 0 2364 0 4 1 NPIR51FL$v024=1, NPIR51FL$v025=2 2
I used rbind function.
code was d2 <-rbind(n11, n16)
I found the following error. How can I fix this?
Error: Can't convert from <labelled<double>> to <labelled<double>> due to loss of precision.
* Locations: 5723, 5724, 5725, 5726, 5727, 5728, 5729, 5730, 5731, 5732, 5733, 5734, 5735, 5736, 5...
Values are labelled in `` but not in ``.
Run `rlang::last_error()` to see where the error occurred.

I have found the solution now.
We can use full_join function of dplyr package to solve this.
d2<- full_join(n11, n16)

Related

ActiveRecord::Fixture::FixtureError: table has no columns named "false"

I am getting the error: ActiveRecord::Fixture::FixtureError: table "creatures" has no columns named "false". I have no column named false in this model.
What is going on?
Here is my fixture:
3 one:
4 name: MyString
5 no: 1
6 type1: 1
7 type2: 1
8 total: 1
9 hp: 1
10 attack: 1
11 defense: 1
12 special_attack: 1
13 special_defense: 1
14 speed: 1
15 generation: 1
16 legendary: false
17
Putting the no in single quotes solved the problem.
If I put a debugger call just before the error is raised:
[475, 484] in /usr/local/bundle/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/database_statements.rb
475: fixture = fixture.stringify_keys
476:
477: unknown_columns = fixture.keys - columns.keys
478: if unknown_columns.any?
479: debugger
=> 480: raise Fixture::FixtureError, %(table "#{table_name}" has no columns named #{unknown_columns.map(&:inspect).join(', ')}.)
481: end
482:
483: columns.map do |name, column|
484: if fixture.key?(name)
(byebug) fixtures
It looks like the no got interpreted as a false:
[{"name"=>"MyString", false=>1, "type1"=>1, "type2"=>1, "total"=>1, "hp"=>1, "attack"=>1, "defense"=>1, "special_attack"=>1, "special_defense"=>1, "speed"=>1, "genneration"=>1, "legendary"=>false, "created_at"=>2023-02-05 18:53:31.63881045 UTC, "updated_at"=>2023-02-05 18:53:31.63881045 UTC, "id"=>980190962}, {"name"=>"MyString", false=>2, "type1"=>1, "type2"=>1, "total"=>1, "hp"=>1, "attack"=>1, "defense"=>1, "special_attack"=>1, "special_defense"=>1, "speed"=>1, "genneration"=>1, "legendary"=>false, "created_at"=>2023-02-05 18:53:31.63881045 UTC, "updated_at"=>2023-02-05 18:53:31.63881045 UTC, "id"=>298486374}]
Putting the no in single quotes solved the problem:
3 one:
4 name: MyString
5 'no': 1
6 type1: 1
7 type2: 1
8 total: 1
9 hp: 1
10 attack: 1
11 defense: 1
12 special_attack: 1
13 special_defense: 1
14 speed: 1
15 generation: 1
16 legendary: false
17
18 two:
19 name: MyString
20 'no': 2
21 type1: 1
22 type2: 1
23 total: 1
24 hp: 1
25 attack: 1
26 defense: 1
27 special_attack: 1
28 special_defense: 1
29 speed: 1
30 generation: 1
31 legendary: false

Print and save to excel issues

I have the following script and I have problems on >printing and
saving. Any ideas or help welcome.
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [3513, 3514, 3517],
'B':['lname1', 'lname2', 'lname3'],
'C':['fname1', 'fname2', 'fname3'],
},index=np.arange(3,dtype=int))
def vamos(df):
for x in df.index:
s = (df.loc[x,'A'])
digits = list(map(int, str(s)))
Sum = (sum(digits))
df = df.assign(column_2=(Sum))
df['column_3'] = 20 - Sum
print(df)
df.to_excel("book_Sum.xlsx")
if __name__ == '__main__':
vamos(df)
This is what I get with print(df):
A B C column_2 column_3
0 3513 lname1 fname1 12 8
1 3514 lname2 fname2 12 8
2 3517 lname3 fname3 12 8
A B C column_2 column_3
0 3513 lname1 fname1 13 7
1 3514 lname2 fname2 13 7
2 3517 lname3 fname3 13 7
A B C column_2 column_3
0 3513 lname1 fname1 16 4
1 3514 lname2 fname2 16 4
2 3517 lname3 fname3 16 4
And this when I save to excel. df.to_excel("book_Sum.xlsx")
A B C column_2 column_3
0 3513 lname1 fname1 16 4
1 3514 lname2 fname2 16 4
2 3517 lname3 fname3 16 4

Define a function : Fibonacci Sequence

Define a function to implement Fibonacci Sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34. Please use the function output first 20 figures of Fibonacci Sequence.
Here is a python implementation
def fib(n):
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
fib(5000)
Output
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
A recursive implementation
memo = [-1] * 21
memo[0] = 0
memo[1] = 1
print(memo[0], end=' ')
print(memo[1], end=' ')
def fibrec(n):
if(memo[n] == -1):
memo[n] = fibrec(n-2) + fibrec(n-1)
print(memo[n], end=' ')
return memo[n]
fibrec(20)
Output
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765

What does the "*A" and "*U" means in the "sctp assocs" display?

cat /proc/net/sctp/assocs
ASSOC-ID ASSOC SOCK STY SST ST HBKT TX_QUEUE RX_QUEUE UID INODE LPORT RPORT LADDRS <-> RADDRS HBINT INS OUTS MAXRT T1X T2X RTXC wmema wmemq sndbuf rcvbuf
13 ffff8800b93a9000 ffff8800ac752300 2 1 3 9176 0 0 0 20735 3905 48538 *192.168.44.228 <-> *A172.16.236.92 7500 10 10 2 0 0 23 1 0 2000000 2000000
0 ffff88042aea3000 ffff880422e88000 0 10 1 40840 0 0 0 9542 3868 3868 *10.127.58.66 <-> *U10.127.115.194 7500 17 17 10 0 0 0 1 0 8388608 8388608

Parsing Blocks of Data in REBOL

I have (games scores) data in this format:
Hotspurs Giants 356 6 275 4 442 3
Fierce Lions Club 371 3 2520 5 0 4
Mountain Tigers 2519 2 291 6 342 1
Shooting Stars Club 2430 5 339 1 2472 2
Gun Tooters 329 4 2512 2 2470 6
Banshee Wolves 301 1 2436 3 412 5
The first two/three words represent the club's names, thereafter follows 6 blocks of data per row which represents the club's round-by-round scores and opponent index (starting from 1). In the data above 3 rounds have been played by each team. Hotspurs Giants (index 1) played Banshee Wolves (6) in the 1st round scoring 356 to Banshee's 301, in round 2 Hotspurs Giants played Shooting Stars Club (4) scoring 275 - 339 and in round 3 played Mountain Tigers (3) scoring 442 to Tiger's 342
My question is how to parse this blocks of data in the most efficient way possible such that each club's data will be in the format below considering that a club's name may comprise of two (2) or more words.
Viz
[Club Round Score Opponent Opponent-Score] for each club
Assuming data is:
data: [
Hotspurs Giants 356 6 275 4 442 3
Fierce Lions Club 371 3 2520 5 0 4
Mountain Tigers 2519 2 291 6 342 1
Shooting Stars Club 2430 5 339 1 2472 2
Gun Tooters 329 4 2512 2 2470 6
Banshee Wolves 301 1 2436 3 412 5
]
I think this solves the problem, please check the result:
clubs: copy []
parse data [
some [
copy club some word!
copy numbers some number!
(append clubs reduce [form club numbers])
|
skip
]
]
new-line/all/skip clubs yes 2
list: copy []
parse clubs [
some [
set club string! into [
copy numbers some number! (
i: 1
foreach [score index] numbers [
append list reduce [
club score
pick clubs index * 2 - 1
pick pick clubs index * 2 i
]
i: i + 2
]
)
]
| skip
]
]
new-line/all/skip list yes 4
Afterwards if you probe clubs you should get:
CLUBS is a block of value: [
"Hotspurs Giants" [356 6 275 4 442 3]
"Fierce Lions Club" [371 3 2520 5 0 4]
"Mountain Tigers" [2519 2 291 6 342 1]
"Shooting Stars Club" [2430 5 339 1 2472 2]
"Gun Tooters" [329 4 2512 2 2470 6]
"Banshee Wolves" [301 1 2436 3 412 5]
]
And if you probe list the output is:
LIST is a block of value: [
"Hotspurs Giants" 356 "Banshee Wolves" 301
"Hotspurs Giants" 275 "Shooting Stars Club" 339
"Hotspurs Giants" 442 "Mountain Tigers" 342
"Fierce Lions Club" 371 "Mountain Tigers" 2519
"Fierce Lions Club" 2520 "Gun Tooters" 2512
"Fierce Lions Club" 0 "Shooting Stars Club" 2472
"Mountain Tigers" 2519 "Fierce Lions Club" 371
"Mountain Tigers" 291 "Banshee Wolves" 2436
"Mountain Tigers" 342 "Hotspurs Giants" 442
"Shooting Stars Club" 2430 "Gun Tooters" 329
"Shooting Stars Club" 339 "Hotspurs Giants" 275
"Shooting Stars Club" 2472 "Fierce Lions Club" 0
"Gun Tooters" 329 "Shooting Stars Club" 2430
"Gun Tooters" 2512 "Fierce Lions Club" 2520
"Gun Tooters" 2470 "Banshee Wolves" 412
"Banshee Wolves" 301 "Hotspurs Giants" 356
"Banshee Wolves" 2436 "Mountain Tigers" 291
"Banshee Wolves" 412 "Gun Tooters" 2470
]
Here is one example (using Rebol 3) showing how this could be done:
club-data: map [] ; store data in hash map is one option
foreach line read/lines %games-scores.txt [
fields: split line space
; lets take last 6 cols of data
scores: reverse collect [loop 6 [keep to-integer take/last fields]]
; and whats left is the club name
club-name: form fields
; build club data
club-data/(club-name): scores
]
Above assumes data is in file games-scores.txt and returns you a MAP! (hash map) called club-data where your club data would look like this:
make map! [
"Hotspurs Giants" [356 6 275 4 442 3]
"Fierce Lions Club" [371 3 2520 5 0 4]
"Mountain Tigers" [2519 2 291 6 342 1]
"Shooting Stars Club" [2430 5 339 1 2472 2]
"Gun Tooters" [329 4 2512 2 2470 6]
"Banshee Wolves" [301 1 2436 3 412 5]
]
One caveat... READ/LINES will load whole file into memory. So if games-scores.txt is big you should look at using OPEN instead and read in one line at a time.
Update - re: your comment here is same example in Rebol 2 [tested in REBOL/Core 2.7.8.2.5 (2-Jan-2011)]:
club-data: make hash! [] ; of course doesn't have to be hash!
foreach line read/lines %games-scores.txt [
fields: parse line none
scores: reverse collect [loop 6 [keep to-integer take/last fields]]
club-name: form fields
append club-data reduce [club-name scores]
]

Resources