如何将.tsf文件读取到python pandas中的数据帧?

时间:2017-02-28 13:05:31

标签: python pandas dataframe

我有一个.tsf文件。

我希望通过指定路径将其读取到pandas中的数据框中。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

如果您通过TSF参考制表符分隔字段,则需要使用Public Shared Event Kickoff(ByVal homeTeamKickingOff As Boolean) Public Shared Event KickoffRet(ByVal kickReturner As Integer) Public Shared Event Touchback(onKickoff As Boolean) Public Sub New() 'MyBase.New(homeTeamId, awayTeamId) 'Add Event Handlers AddHandler Kickoff, AddressOf KickoffEvt AddHandler KickoffRet, AddressOf KickoffRetEvt AddHandler Touchback, AddressOf TouchbackEvt End Sub Public Shared Sub KickoffRetEvt(kickReturner As Integer) Dim MyRand As New MersenneTwister Dim GenKickRetYds As New MersenneTwister Select Case MyRand.GenerateInt32(0, 100) Case 0 To 80 KickReturnYards = GenKickRetYds.GenerateInt32(10, 30) Case 71 To 90 KickReturnYards = GenKickRetYds.GenerateInt32(31, 40) Case 91 To 97 KickReturnYards = GenKickRetYds.GenerateInt32(41, 60) Case Else KickReturnYards = GenKickRetYds.GenerateInt32(61, 100) End Select End Sub Public Overridable Sub TouchbackEvt(onKickoff As Boolean) 'If its a touchback from a kickoff, the ball is placed at the 25 yard line, otherwise at the 20 YardLine = If(onKickoff, 25, 20) Down = 1 End Sub ''' <summary> ''' Handles the kickoff Event ''' </summary> Public Shared Sub KickoffEvt(homeTeamKickingOff As Boolean) Dim MyRand As New MersenneTwister() HomePossession = If(homeTeamKickingOff, False, True) 'This is the same as HomePossesion = homeTeamKickingOff ? True : False in C# If MyRand.GenerateInt32(0, 100) < 40 Then '39% of kicks are returned, otherwise touchback Dim HomeKOR = FindPlayerId(Stats, "WR4", HmTeamId) 'Home Kickoff Returner Dim AwayKOR = FindPlayerId(Stats, "WR4", AwTeamId) 'AWay Kickoff Returner Dim KR = If(HomePossession, HomeKOR, AwayKOR) RaiseEvent KickoffRet(KR) Else RaiseEvent Touchback(True) End If End Sub

pandas.read_csv('filename.tsf', sep='\t')会告诉大熊猫这些字段是由标签分隔的。