Click here to Skip to main content
14,580,625 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am new in python. I am getting two python list 'ad' and 'ttf' in the following code

code 1:

train_df = pd.read_csv('train.csv', dtype={'acoustic_data': np.int16, 'time_to_failure': np.float32})
  ad = pd.DataFrame()
  ttf = pd.Series()
  
 
  failure_idxs = [5656574,  50085878, 104677356, 138772453, 187641820, 218652630,
                    245829585, 307838917, 338276287, 375377848, 419368880, 461811623,
                    495800225, 528777115, 585568144, 621985673]

        
  for idx in failure_idxs:
      ad = train_df['acoustic_data'].values[idx - 150000: idx + 30000]
      ttf = train_df['time_to_failure'].values[idx - 150000: idx + 30000]
      print("ad=",ad)    #python list
      print("ttf=",ttf)   #python list
      break


Output 1:

It prints out this

  ad= [1 4 9 ... 8 6 5]
ttf= [ 0.03909828  0.03909828  0.03909827 ... 11.5332985  11.5332985
 11.5332985 ]


Here is data generated by 'pd.read_csv' by using 'iterator' and 'chunksize'
Code 2:
train1 = pd.read_csv('train.csv', iterator=True, chunksize=150000, dtype={'acoustic_data': np.int16, 'time_to_failure': np.float64})
      X_train = pd.DataFrame()
      y_train = pd.Series()
      for df in train1:
          print("acoustic_data=",df['acoustic_data'])     #data printed
          print("time_to_failure=",pd.Series(df['time_to_failure'].values[-1]))   #data printed
          ch = gen_features(df['acoustic_data'])
          break


Output 2: Data printed by 'pd.read_csv' by using 'iterator' and 'chunksize' is like this

acoustic_data= 0         12
1          6
2          8
3          5
4          8
          ..
149995     1
149996     6
149997     6
149998     2
149999     0
Name: acoustic_data, Length: 150000, dtype: int16
time_to_failure= 0         1.469100
1         1.469100
2         1.469100
3         1.469100
4         1.469100
  
149995    1.430797
149996    1.430797
149997    1.430797
149998    1.430797
149999    1.430797
Name: time_to_failure, Length: 150000, dtype: float64


My function "ch = gen_features(df['acoustic_data'])" accepts input data generated by 'pd.read_csv' by using 'iterator' and 'chunksize'.How i can convert two simple python list 'ad' and 'ttf' into data generated by 'pd.read_csv' that use 'iterator' and 'chunksize'?

I simply mean how to programmatically convert output 1 to just like output 2 by using code 1?

ouput 2 has the index number with along with tab-separated values that are printed...while output 1 is just the list of values ...How I can programmatically convert output 1 in the format of output 2?

You can download the sample code from this link and run using python ide like spyder pychar etc .

What I have tried:

Python Lists  |  Python Education  |  Google Developers[^]
Posted
Updated 28-Jun-20 6:22am
v4
Comments
Richard MacCutchan 28-Jun-20 12:49pm
   
The default for printing a list is to print it in the format that it appears in code. If you want it printed in a specific form then you need to iterate through the items and print each separate item in the format you require.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100