Question

Hi it's python I imported a data which are so many words in txt and I arranged and reshaped with alphabetically both rows and columns

I was successful with these steps but I am stuck with next step

below is my code and screenshot

import numpy as np
import pandas as pd

data=pd.read_csv("/Users/superman/Downloads/words_file2.txt",header=None)
df_input=pd.DataFrame(data)
df_output=pd.DataFrame(np.arange(676).reshape((26,26)),
index = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'],
columns = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'])
df_output.index.name="Start"
df_output.columns.name="End"
df_output

End a b cd e f g h j..qrtuV Wxy z Start a 0 2 3 4 5 6 78 9 ...16 17 18 19 20 21 22 23 24 25 ь26 27 28 29 30 31 32 33 34 35 c

This below screen shot is what I have to find

I have to find each word from input data frame (which is txt file) which its start and end character and add the count into the output data frame.

So for example let's say there's adbkqa , it starts with a and ends a so it counts 1 between start a and a end, so add 1 to the current value. another example which starts a and end z is not into the txt so it counts 0 like below screenshot.

Maybe my first step might be wrong (one condition is all data initially in this data frame are zeros) <- I don't get it so

please help me to get a correct answer like below code please help!

the txt file is here

https://drive.google.com/open?id=1VXtEPNBJ6ypJZ62ypeeWtzS9TjcGhBp4

End a b cd e fg h .q rstuv wxy z Start a 2 0 10 7 48 1 2 2 0 0.. 0 3 11 15 0 0 01 11 0 b 00 1 2 4 0 0 6 0 0.. 0 0 4 0 0 00 1

End a b cd e f g h j..qrtuV Wxy z Start a 0 2 3 4 5 6 78 9 ...16 17 18 19 20 21 22 23 24 25 ь26 27 28 29 30 31 32 33 34 35 c 52 53 54 55 56 57 58 5960 61 d 78 79 80 8 82 83 84 85 86 87 42 43 44 45 46 4748 49 50 51 68 69 70 71 72 73 74 75 76 77 9495 96 97 98 99100 101 102 103 f 130 131 132 133 134 135 136 137 138 139 146 147 148 149 150 151 152 153 154 155 g 156 157 158159 160 161 162 163 164 165 172 173 174 175 176 177 178 179180 181 198 199 200 201 202 203 204 205 206 207 i 208 209 210 211 212 213 214 215 216 217 224 225 226 227 228 229 230 231 232 233 j 234 235 236 237 238 239 240 241 242 243 250 251 252 253 254 255 256 257 258 259 k 260 261 262 263 264 265 266 267268 269 ...276 277 278 279 280 281 282 283 284 285 295 302 303 304 305 306 307 308 309 310 311 m 312 313 314 315 316 317 318 319 320 321 ...328 329 330 331 332 333 334 335 336 337 n 338 339 340 341 342 343 344 345 346 347 354 355 356 357 358 359 360 361 362 363 o 364 365 366 367 368 369 370 371 372 373 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 406 407 408 409 410 411 412 413 414 415 q 416 417418 419 420 421 422 423 424 425 ...432 433 434 435 436 437 438 439 440 441 458 459 460 461 462 463 464 465 466 467 h 182 183 184 185 186 187 188 189 190 191 I 286 287 288 289 290 291 292 293 294 r 442 443 444 445 446 447 448 449 450451
End a b cd e fg h .q rstuv wxy z Start a 2 0 10 7 48 1 2 2 0 0.. 0 3 11 15 0 0 01 11 0 b 00 1 2 4 0 0 6 0 0.. 0 0 4 0 0 00 1 0 c1 0 1 5 38 0 410 0...0 3 14 21 0 0 00 13 0 d 0 0 3 5 36 0 1 3 00..0 4 6 12 0010 6 0 e 0 0 5 3 24 0 0 110..0 3 3 16 0010 7 0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

import numpy as np
import pandas as pd

data=pd.read_csv('words_file2.txt',header=None)

data.head()

df_output=pd.DataFrame(np.zeros(676,dtype=int).reshape((26,26)),
index = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'],
columns = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'])
df_output.index.name="Start"
df_output.columns.name="End"
df_output

#Here I have mentioned first i[-1] because in DataFrame first index goes for column
#so we go for End as we mentioned the Row name
for i in data[0]:
df_output[i[-1]][i[0]]+=1

df_output

OUTPUT:

In [15]: df output-pd.DataFrame (np.zeros (676,dtype-int).reshape( (26,26, index [a, b,c,d,e,f,g,h,i,j,k

In [24]: #Here I have mentioned first ǐ[-1] because in DataFrame first index goes for column #50 we go for End as we mentione

#If you have any queries feel free to comment

Add a comment
Know the answer?
Add Answer to:
Hi it's python I imported a data which are so many words in txt and I arranged and reshaped with ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi it's my code for python I almost finished my project but only one thing left which is most con...

    Hi it's my code for python I almost finished my project but only one thing left which is most confusing part please help me I have to find most occurring ending character from a to z For instance, output should be like this I have to find a to z. Words starting with ‘a’ end mostly with ‘O’ Words starting with ‘b’ end mostly with ‘O’ ...... No words start with ‘O’(If there's no word in the character from a...

  • why is this wrong for vectors vector<char> decrypt{ {'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',...

    why is this wrong for vectors vector<char> decrypt{ {'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A'}, {'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'}, }; for(int...

  • Write a program in Python to read the .txt file . Then to plot CO2_flux against...

    Write a program in Python to read the .txt file . Then to plot CO2_flux against time for every half hour . A H P DATAH DATAU DATA DATA DATA DATA 0 0 DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA DATA B C D E F G filename date t ime DOY daytime file_records used_record: Tau qc_Tau [yyyy-mm-de (HH:MM] [ddd.ddd]...

  • So I'm currently doing coding in Python. There's two parts and we're supposed to use loops...

    So I'm currently doing coding in Python. There's two parts and we're supposed to use loops and nested loops to produce the following outputs: part A) 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 .... for ten times in total part B) 0 0 0 0 0 0...

  • (B)(C)(D)(E)(G)(I)(J) 39 Write the Taylor expansion of function f order n at to given below. 1...

    (B)(C)(D)(E)(G)(I)(J) 39 Write the Taylor expansion of function f order n at to given below. 1 (a) (g)2+v1+ I, n 2,ro - 0 n = 7, xo = 0 1 -2-3 (b) sin z cos(2x), (c) z In(2+3z), VI+I n= 3, To = 0 1 +e-1/ (h) 2+x n =5,xo= +o0 n= 3, ro = 1 T (i) cos (2r), n 4, xo= 6 (d) n = 7,xo = 0 COSI i) V+-VI3-, n 4, 1o =+00 (e) In(1+ arcsin(2r)),...

  • Please Solove only (a)and (b) Please, Write so that I can recognize 4.20 Consider the system...

    Please Solove only (a)and (b) Please, Write so that I can recognize 4.20 Consider the system depicted in Fig. P4.20(a). The of the input signal is depicted in Fig. P4.20(b). I FT FT z(t) Z(jw) and y(t) Z(ja) and Y(jo) for the following cases: -» Y(j»). Sket (a) w(t) cos(5 mt) and h(t) sin 6 (b) w(t) cos(5mt) and h(t) sin 5 (c) w(t) depicted in Fig. P4.20(c) and h(t) sin2r cos (5 rt X(jw) z(t) x)X hit) w(t) cos...

  • Hello everyone. I have a bankers algorithm written in java that gets inputs from a .txt...

    Hello everyone. I have a bankers algorithm written in java that gets inputs from a .txt file. The file has 7 processes and 5 resources however, when the program runs, it doesn't sum the resource columns correctly. The program runs correctly for smaller matricies (4 processes, 3 resources), not sure what the issue is and have been looking over the code for awhile so maybe another set of eyes would help...thanks BankersAlgorithm.java /** * This program implements Bankers algorithm which...

  • Create a graph in python for a given input series without using any libraries

    I was asked this question:Given any input series a corresponding graph must be generated without the use of any libraries.After, trying my best, I arrived at this solution to which they replied it had a logical issue.# Create the matrix print("Enter the sequence with spaces: ") arr = list(map(int, input().split())) count = len(arr) rows = int(sum(arr))  cols = int(sum(arr) + 4) content = [[" "]*cols for _ in range(rows)] maxq = 0 maxp = 0 content[0][0] = "/" # Apply the positions in the matrix p = 0 q = arr[0] k = 0 for l in range(q):     if (k != q):         content[k][p] = "/"         p = p + 1         k = k + 1 p = q flag = 1 i = 0 j = 0 k = 0 c = 0 temp = 0 r = 0 flag = 1 for i,j in enumerate(arr):     c = c + 1     if c < count:         k = arr[i+1]     else:         k = 0     if arr[i]:         if flag == 1:             content[q][p] = "/\\"             if maxq < q:                 maxq = q                 maxp = p             qori = q             pori = p             p = p + k             temp = q - k...

  • i Data Table Table 2. INVENTORY RECORD DATA F G C Data Category Lot-sizing rule Lead...

    i Data Table Table 2. INVENTORY RECORD DATA F G C Data Category Lot-sizing rule Lead time Safety stock Scheduled receipts Beginning inventory L4L 3 weeks 0 150 (week 2) 125 D FOQ = 800 3 weeks 0 300 (week 2) 0 Item E FOQ = 600 4 weeks 0 600 (week 1) 255 L4L 2 weeks 70 None 670 L4L 1 week 0 1,200 (week 1) 0 Print Done Done nd then click Check Answer. Clear All The BOM...

  • This is a c++ question note: not using  namespace std; at the beginning of the program Writing...

    This is a c++ question note: not using  namespace std; at the beginning of the program Writing Data to a File This program will write a series of letters, starting with 'A', to an external file (letters.txt). The user will decide how many letters in total get saved to the file. ** IMPORTANT: The test cases will evaluate your code against .txt files that I uploaded. You do NOT have to upload your own txt files. Input: Including 'A', how many...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT