0

I just started using Python and i am trying to understand the process of data manipulations here in python.

I use the following piece of code to fetch my required data.

cert = r"cacert.pem"
os.environ["REQUESTS_CA_BUNDLE"] = cert
kerberos = HTTPKerberosAuth(mutual_authentication=OPTIONAL)
session = requests.Session()

link = 'file.txt'
data=session.get(link,auth=kerberos,verify=False).content.decode("latin-1")

Since the data source needs to be authorised, this is essentially the only way I can extract data.

The variable data is basically a txt file. How can I convert this to a dataframe or any useful data structure for further analysis..

jack ryan
  • 61
  • 7
  • 1
    I think you should provide an example of how is the inputted string "pattern". You can do approaches with lists (split method), dictionaries, and other creative (more pythonic) approaches. Check [this link](https://stackoverflow.com/questions/22604564/create-pandas-dataframe-from-a-string) for an example. – Alexander Santos Oct 09 '19 at 14:42
  • @AlexanderSantos The data is essentially delimited by space. How do I go about it? – jack ryan Oct 09 '19 at 14:49
  • you can use the same approach from link, but as sep you can add " ". Like this: `df = pd.read_csv(TESTDATA, sep=" ")`. This will make all spaces a separator though, so if you have a word that uses space and shouldn't be used as separator for the dataframe, it can break it. – Alexander Santos Oct 09 '19 at 15:02
  • @AlexanderSantos But I am not reading it from my desktop or any place else. Ive extracted the data from an online txt file as mentioned. The variable is already in my environment. Doesn't reading it seem counter intuitive? – jack ryan Oct 09 '19 at 15:42
  • I mean, his reply it's not like creating a new file to re-read. It's like using a string as I/O (buffer) to convert into DataFrame – Alexander Santos Oct 09 '19 at 16:23

0 Answers0