Python/C2/loading-data-from-files/Gujarati

From Script | Spoken-Tutorial
Revision as of 16:54, 11 October 2013 by Jyotisolanki (Talk | contribs)

Jump to: navigation, search
Visual Cue Narration
0:01 નમસ્કાર મિત્રો "loading data from files" પરનાં આ સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે.
0:06 આ ટ્યુટોરીયલની અંતમાં, તમે આપેલ વિશે સમર્થ હશો,

૧. ડેટાની એકલ કોલમ ધરાવતી, ફાઈલમાંથી ડેટા વાંચવું ૨. ડેટાની બહુવિધ કોલમને વાંચવું, જે ખાલી જગ્યાથી અથવા બીજા કોઈ વિભાજકોથી જુદી કરાયી હોય.

0:19 ipython હાયફન pylab વાપરીને, ચાલો ટર્મિનલ પર જઈએ અને IPython ચાલુ કરીએ.
0:33 હવે, ચાલો loadtxt કમાંડ વાપરીને, primes.txt ફાઈલ વાંચવાથી શરૂઆત કરીએ, જે કોલમમાં યાદીબદ્ધ થયેલ પ્રાથમિક ક્રમાંકોની યાદી ધરાવે છે.
0:45 કૃપા કરી એ વાતની ખાતરી કરી લો કે તમે 'primes.txt', ફાઈલનો યોગ્ય માર્ગ આપ્યો છે.
0:50 ફાઈલ, અમારા કિસ્સામાં, સ્લેશ હોમ સ્લેશ fossee સ્લેશ primes.txt માં હાજર છે.
0:59 અન્યથા આપણે ફાઈલનો પત્તો મેળવવા માટે cat કમાંડ વાપરી શકીએ છીએ અને તેમાંનાં ઘટકોને વાંચી શકીએ છીએ.
1:05 તો ટાઈપ કરો cat સ્લેશ home સ્લેશ fossee સ્લેશ primes.txt
1:15 હવે ચાલો વેરીએબલ પ્રાઈમમાંની આ યાદી વાંચીએ.
1:20 તો ટાઈપ કરો primes = loadtxt કૌંસમાં એકલ અવતરણમાં સ્લેશ home સ્લેશ fossee સ્લેશ primes.txt
1:41 પ્રાઈમ્સ હવે પ્રાથમિક ક્રમાંકોનો એક અનુક્રમ છે, જે ``primes.txt``, ફાઈલમાં યાદીબદ્ધ કરાયેલ હતો.
1:49 આપણે હવે ટાઈપ કરીએ છીએ primes,print primes એ જોવા માટે કે અનુક્રમ પ્રીંટ થયો છે કે નહી તો ટાઈપ કરો print સ્પેસ primes.
2:00 આપણે અવલોકન કરીએ છીએ કે તમામ ક્રમાંકો એક અંતર સાથે અંત થાય છે.
2:04 આ એટલા માટે, કારણ કે આ ક્રમાંકો વાસ્તવમાં ફ્લોટ્સ તરીકે વંચાય છે
2:10 હવે, ચાલો આપણે pendulum.txt ફાઈલને વાંચવા માટે loadtxt કમાંડનો ઉપયોગ કરીએ જે ડેટાની બે કોલમ ધરાવે છે.
2:19 આ ફાઈલ પહેલી કોલમમાં લોલકની લંબાઈ ધરાવે છે અને અનુરૂપ સમયગાળો બીજા કોલમમાં ધરાવે છે.
2:26 નોંધ લો કે અહીં loadtxt માટે બંને કોલમ સરખા ક્રમાંકમાં હરોળો ધરાવે એ જરૂરી છે.
2:31 આ ફાઈલનાં ઘટકોને જોવા માટે આપણે cat કમાંડ વાપરી શકીએ છીએ.
2:36 તો ટાઈપ કરો cat સ્લેશ home સ્લેશ fossee સ્લેશ pendulum.txt
2:50 ચાલો હવે, વેરીએબલ pend માંના ડેટાને વાંચીએ.
2:55 ફરીથી, તે ધારે છે કે ફાઈલ સ્લેશ home સ્લેશ fossee માં છે
3:02 તો ટાઈપ કરો pend = loadtxt કૌંસમાં એકલ અવતરણમાં સ્લેશ home સ્લેશ fossee સ્લેશ pendulum.txt
3:21 ચાલો આપણે હવે વેરીએબલ pend ને પ્રીંટ કરીએ અને જોઈએ તે શું ધરાવે છે.
3:26 તો ટાઈપ કરો print pend
3:31 નોંધ લો કે pendprimes ની જેમ સાદો અનુક્રમ નથી.
3:35 તે બે અનુક્રમ ધરાવે છે, ડેટા ફાઈલની બંને કોલમોનો સમાવેશ કરીને.
3:40 તેને બે જુદા, સામાન્ય અનુક્રમમાં વાંચવા માટે, ચાલો load txt કમાંડની વધારાની આર્ગ્યુંમેંટનો ઉપયોગ કરીએ.
3:50 તો ટાઈપ કરો L, T space = space load txt કૌંસમાં એકલ અવતરણમાં સ્લેશ home સ્લેશ fossee સ્લેશ pendulum.txt અલ્પવિરામ unpack=True
4:23 ચાલો આપણે હવે, વેરીએબલ ''L અને T ને પ્રીંટ કરીએ, એ જોવા માટે કે એ શું ધરાવે છે.
4:29 તો ટાઈપ કરો print space L

print space T

4:39 નોંધ લો, કે L અને T હવે pendulum.txt, ડેટા ફાઈલમાંથી પહેલી અને બીજી ડેટાની કોલમો ધરાવે છે, અને તે બંને સાદા અનુક્રમ છે.
4:50 unpack=True આપણને બે કોલમો એક જટિલ અનુક્રમનાં બદલે બે જુદા જુદા અનુક્રમમાં આપી છે.
5:00 હમણાં સુધી, આપણે load txt કમાંડનો સામાન્ય ઉપયોગ શીખ્યા છીએ.
5:05 ચાલો એક ઉદાહરણ પ્રયાસ કરીએ.
5:07 Pause the video here, try out the following exercise and resume the video.
5:12 Read the file pendulum underscore semicolon.txt which contains the same data as pendulum.txt, but the columns are separated by semi-colons instead of spaces.
5:27 Use the IPython help to see how to do this.
5:34 Switch back to the terminal

L comma T = loadtxt within bracket in single quote slash home slash fossee slash pendulum underscore semicolon.txt comma unpack=True comma

              delimiter=semi-colon within single quote
6:54 Okay then type print L
6:40 print T
6:45 This brings us to the end of this tutorial.
6:48 In this tutorial, we have learnt to,
6:51 1. To Read data from files, containing a single column of data using the loadtxt command.
6:58 2. To Read multiple columns of data, separated by spaces or other delimiters.
7:04 Here are some self assessment questions for you to solve

1. loadtxt can read data from a file with one column only. True or False?

7:18 2. Given a file data.txt with three columns of data separated by spaces, read it into 3 separate simple sequences.
7:29 3. Given a file data.txt with three columns of data separated by ":", read it into 3 separate simple sequences.
7:45 And now the answers,1. False.
7:50 loadtxt command can read data from files having both single columns as well as multiple columns.
7:58 2. A file with three columns of data separated by spaces to be read into 3 separate sequences, we use the loadtxt command as, x = loadtxt within bracket in double quotes data.txt comma unpack=True
8:19 3. If a file with three columns of data separated by delimiters,we read it into three separate sequences by using an additional argument of delimiter in the loadtxt command

x = loadtxt within bracket in double quotes data.txt comma unpack=True comma delimiter=in double quotes semicolon)

8:51 Hope you have enjoyed this tutorial and found it useful.
8:55 Thank you!

Contributors and Content Editors

Jyotisolanki