VB import Text file into Excel\VB - vb.net

I have the following text file which I'm trying to automate into a line Graph in excel.. which logs every 5 minutes up until from 08:00 till 18:00 so there is quite a few rows
TIME Rec-Created Rec-Deleted Rec-Updated Rec-read Rec-wait Committed bi- writes Bi-reads DB-Writes DB-READ db-access Checkpoints Flushed
08:09:00 37 0 5 21276 0 1894 33 3 109 43 47691 1 0
08:14:00 49 0 144 20378 0 1225 143 0 88 192 53377 0 0
08:19:00 44 0 237 19902 0 1545 283 6 317 120 49668 2 0
08:24:00 51 0 129 12570 0 626 191 3 164 58 37811 1 0
08:29:00 61 0 49 14138 0 541 86 3 116 77 36836 1 0
08:34:00 59 0 144 58536 0 1438 209 3 143 3753 135427 1 0
08:39:00 85 0 178 28309 0 1822 209 6 209 80 70950 2 0
08:44:00 57 0 157 17940 0 554 132 3 170 92 47561 1 0
08:49:00 115 0 217 29961 0 1867 186 3 333 193 76057 1 0
08:54:00 111 0 225 23320 0 540 198 6 275 246 64138 2 0
08:59:00 41 0 152 15638 0 359 187 3 368 103 44558 1 0
I'm not too concerned about the Line graph part but more the trying to get the data into excel in the correct format.
I'm assuming I would need to use an array, but currently that is little advanced for me at the moment as Im still trying to get to grips VB and this is really my first venture into this world...(as you can see from my previous post)
any help or guidance would be appreciated..
(im studying the VB for Dummies and Visual Basic Fundamentals: Development for Absolute Beginners from the channel9 MSDN)
thanks in advance

I would probably create typed dataset, with all of your columns. Lets call it YourDataset.
Then read the file in and add rows to your table for each row in the file. Not fully functional but an outline of a solution.
dim typedDataset = new YourDataset
Using reader As StreamReader = New StreamReader("file.txt")
line = reader.ReadLine
dim rowData = line.Split(" ")
'add a new row to typed dataset based on data above
End Using
That is how you would get your data into vb.net, it would be sitting in a table just like the excel table, at that point if you didn't care about excel you could use a graphing control like on this page. And see it with a datagrid view https://msdn.microsoft.com/en-us/library/dd489237(v=vs.140).aspx
But going to excel you would need to follow a guide like the one I have in the following link. You need to use the Microsoft.Office.Interop.Excel
http://www.codeproject.com/Tips/669509/How-to-Export-Data-to-Excel-in-VB-NET

Related

how to add a constant value (1) in an empty column in snowflake-matillion

my table looks like
id total avg test_no
1 445 89
2 434 85
3 378 75
4 421 84
I'm working on matillion-snowflake
I need my result to look like
id total avg test_no
1 445 89 1
2 434 85 1
3 378 75 1
4 421 84 1
Just use a Calculator component and set the value of the calculated column to 1
In Snowflake, you would modify the table using:
update t
set test_no = 1;
I assume that Matillion supports this as well.

How to remove unwanted values in data when reading csv file

Reading Pina_Indian_Diabities.csv some of the values are strings, something like this
+AC0-5.4128147485
734 2
735 4
736 0
737 8
738 +AC0-5.4128147485
739 1
740 NaN
741 3
742 1
743 9
744 13
745 12
746 1
747 1
like in row 738, there re such values in other rows and columns as well.
How can I drop them?

Parsing Json Data from select query in SQL Server

I have a situation where I have a table that has a single varchar(max) column called dbo.JsonData. It has x number of rows with x number of properties.
How can I create a query that will allow me to turn the result set from a select * query into a row/column result set?
Here is what I have tried:
SELECT *
FROM JSONDATA
FOR JSON Path
But it returns a single row of the json data all in a single column:
JSON_F52E2B61-18A1-11d1-B105-00805F49916B
[{"Json_Data":"{\"Serial_Number\":\"12345\",\"Gateway_Uptime\":17,\"Defrost_Cycles\":0,\"Freeze_Cycles\":2304,\"Float_Switch_Raw_ADC\":1328,\"Bin_status\":2304,\"Line_Voltage\":0,\"ADC_Evaporator_Temperature\":0,\"Mem_Sw\":1280,\"Freeze_Timer\":2560,\"Defrost_Timer\":593,\"Water_Flow_Switch\":3328,\"ADC_Mid_Temperature\":2560,\"ADC_Water_Temperature\":0,\"Ambient_Temperature\":71,\"Mid_Temperature\":1259,\"Water_Temperature\":1259,\"Evaporator_Temperature\":1259,\"Ambient_Temperature_Off_Board\":0,\"Ambient_Temperature_On_Board\":0,\"Gateway_Info\":\"{\\\"temp_sensor\\\":0.00,\\\"temp_pcb\\\":82.00,\\\"gw_uptime\\\":17.00,\\\"winc_fw\\\":\\\"19.5.4\\\",\\\"gw_fw_version\\\":\\\"0.0.0\\\",\\\"gw_fw_version_git\\\":\\\"2a75f20-dirty\\\",\\\"gw_sn\\\":\\\"328\\\",\\\"heap_free\\\":11264.00,\\\"gw_sig_csq\\\":0.00,\\\"gw_sig_quality\\\":0.00,\\\"wifi_sig_strength\\\":-63.00,\\\"wifi_resets\\\":0.00}\",\"ADC_Ambient_Temperature\":1120,\"Control_State\":\"Bin Full\",\"Compressor_Runtime\":134215680}"},{"Json_Data":"{\"Serial_Number\":\"12345\",\"Gateway_Uptime\":200,\"Defrost_Cycles\":559,\"Freeze_Cycles\":510,\"Float_Switch_Raw_ADC\":106,\"Bin_status\":0,\"Line_Voltage\":119,\"ADC_Evaporator_Temperature\":123,\"Mem_Sw\":113,\"Freeze_Timer\":0,\"Defrost_Timer\":66,\"Water_Flow_Switch\":3328,\"ADC_Mid_Temperature\":2560,\"ADC_Water_Temperature\":0,\"Ambient_Temperature\":71,\"Mid_Temperature\":1259,\"Water_Temperature\":1259,\"Evaporator_Temperature\":54,\"Ambient_Temperature_Off_Board\":0,\"Ambient_Temperature_On_Board\":0,\"Gateway_Info\":\"{\\\"temp_sensor\\\":0.00,\\\"temp_pcb\\\":82.00,\\\"gw_uptime\\\":199.00,\\\"winc_fw\\\":\\\"19.5.4\\\",\\\"gw_fw_version\\\":\\\"0.0.0\\\",\\\"gw_fw_version_git\\\":\\\"2a75f20-dirty\\\",\\\"gw_sn\\\":\\\"328\\\",\\\"heap_free\\\":10984.00,\\\"gw_sig_csq\\\":0.00,\\\"gw_sig_quality\\\":0.00,\\\"wifi_sig_strength\\\":-60.00,\\\"wifi_resets\\\":0.00}\",\"ADC_Ambient_Temperature\":1120,\"Control_State\":\"Defrost\",\"Compressor_Runtime\":11304}"},{"Json_Data":"{\"Seri...
What am I missing?
I can't specify the columns explicitly because the json strings aren't always the same.
This what I expect:
Serial_Number Gateway_Uptime Defrost_Cycles Freeze_Cycles Float_Switch_Raw_ADC Bin_status Line_Voltage ADC_Evaporator_Temperature Mem_Sw Freeze_Timer Defrost_Timer Water_Flow_Switch ADC_Mid_Temperature ADC_Water_Temperature Ambient_Temperature Mid_Temperature Water_Temperature Evaporator_Temperature Ambient_Temperature_Off_Board Ambient_Temperature_On_Board ADC_Ambient_Temperature Control_State Compressor_Runtime temp_sensor temp_pcb gw_uptime winc_fw gw_fw_version gw_fw_version_git gw_sn heap_free gw_sig_csq gw_sig_quality wifi_sig_strength wifi_resets LastModifiedDateUTC Defrost_Cycle_time Freeze_Cycle_time
12345 251402 540 494 106 0 98 158 113 221 184 0 0 0 1259 1259 1259 33 0 0 0 Freeze 10833 0 78 251402 19.5.4 0.0.0 2a75f20-dirty 328.00000000 10976 0 0 -61 0 2018-03-20 11:15:28.000 0 0
12345 251702 540 494 106 0 98 178 113 517 184 0 0 0 1259 1259 1259 22 0 0 0 Freeze 10838 0 78 251702 19.5.4 0.0.0 2a75f20-dirty 328.00000000 10976 0 0 -62 0 2018-03-20 11:15:42.000 0 0
...
Thank you,
Ron

switching every 2nd row value in pandas

My dataframe is a list of football games with varying stats, around 300 entries.
game_id team opp_team avg_marks
0 2919 STK BL 122
1 2919 BL STK 114
2 2920 RICH SYD 135
3 2920 SYD RICH 108
I would like to add the opposition stats as a new column for each entry. Resultant dataframe would appear like this
game_id team opp_team avg_marks opp_avg_marks
0 2919 STK BL 122 114
1 2919 BL STK 114 122
2 2920 RICH SYD 135 108
3 2920 SYD RICH 108 135
Any suggestions would be most welcome, I'm new to this forum. I have tried mapping but the entry is conditional on 2 columns, game_id and opp_team.
Ideally I would add it in original spreadsheet but I created a cumulative average for the season in pandas so was hoping there would be a way to incorporate this as well.
You could group on game_id and reverse the avg_marks values
In [725]: df.groupby('game_id')['avg_marks'].transform(lambda x: x[::-1])
Out[725]:
0 114
1 122
2 108
3 135
Name: avg_marks, dtype: int64
In [726]: df['opp_avg_marks'] = (df.groupby('game_id')['avg_marks']
.transform(lambda x: x[::-1]))
In [727]: df
Out[727]:
game_id team opp_team avg_marks opp_avg_marks
0 2919 STK BL 122 114
1 2919 BL STK 114 122
2 2920 RICH SYD 135 108
3 2920 SYD RICH 108 135
Or, get dict mapping from team and avg_marks, then use map on opp_team
In [729]: df['opp_team'].map(df.set_index('team')['avg_marks'].to_dict())
Out[729]:
0 114
1 122
2 108
3 135
Name: opp_team, dtype: int64

Generate Seaborn Countplot using column value as count

For the following table
count_value
CPUCore Offline_RetentionAge
i7 183 4184
7 1981
30 471
i5 183 2327
7 831
30 250
Pentium 183 333
7 125
30 43
2 183 575
7 236
31 96
Is it possible to generate a seaborn countplot (or normal countplot) like the following (generated using sns.countplot(x='CPUCore', hue="Offline_BackupSchemaIncrementType", data=dfCombined_df))
Problem here is that I need to use the count_value as count, rather then really go and count the Offline_RetentionAge
I think you need seaborn.barplot:
sns.barplot(x="count_value", y="index", hue='Offline_RetentionAge', data=df.reset_index())